upnpharvester/common/cmsettings/src/cmsettingsengine.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2006-2007 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:      CM Settings Engine implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <e32const.h>
       
    25 #include <bautils.h>
       
    26 #include <f32file.h>
       
    27 #include <centralrepository.h>
       
    28 #ifdef __SERIES60_31__
       
    29 #include <upnpnetworkaccess.h>
       
    30 #else
       
    31 #include "upnpsettingsengine.h"
       
    32 #endif
       
    33 #include "cmdriveinfo.h"
       
    34 #include <driveinfo.h>
       
    35 
       
    36 #include "msdebug.h"
       
    37 #include "cmsettingsengine.h"
       
    38 #include "contentmanagercrkeys.h"
       
    39 
       
    40 
       
    41 // Constants
       
    42 
       
    43 const TInt KTimeLength = 64;
       
    44 
       
    45 
       
    46 // ======== MEMBER FUNCTIONS ========
       
    47 
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // Default constructor
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CCmSettingsEngine::CCmSettingsEngine()
       
    54     {
       
    55     }
       
    56 
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // Two-phase constructor
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 void CCmSettingsEngine::ConstructL()
       
    63     {
       
    64     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::ConstructL"));
       
    65 
       
    66     iRepository = CRepository::NewL( KCRUidCmContentManager );
       
    67     }
       
    68 
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // Two-phase API constructor
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CCmSettingsEngine* CCmSettingsEngine::NewL()
       
    75     {
       
    76     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::NewL"));
       
    77 
       
    78     CCmSettingsEngine* self = CCmSettingsEngine::NewLC();
       
    79     CleanupStack::Pop( self );
       
    80     return self;
       
    81     }
       
    82 
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // Two-phase API constructor
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 CCmSettingsEngine* CCmSettingsEngine::NewLC()
       
    89     {
       
    90     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::NewLC"));
       
    91 
       
    92     CCmSettingsEngine* self = new( ELeave ) CCmSettingsEngine;
       
    93     CleanupStack::PushL( self );
       
    94     self->ConstructL();
       
    95     return self;
       
    96     }
       
    97 
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // Destructor
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 CCmSettingsEngine::~CCmSettingsEngine()
       
   104     {
       
   105     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::~CCmSettingsEngine"));
       
   106 
       
   107     delete iRepository;
       
   108     }
       
   109 
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // Gets Content Manager service's state
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 TInt CCmSettingsEngine::GetServiceState(
       
   116     const TCmService aService,
       
   117     TCmServiceState& aState ) const
       
   118     {
       
   119     TInt error( KErrNone );
       
   120     TInt state( 0 );
       
   121 
       
   122     switch ( aService )
       
   123         {
       
   124         case ECmServiceContentManager:
       
   125             {
       
   126             error = iRepository->Get( KCmContentManagerState, state ) ;
       
   127             break;
       
   128             }
       
   129         case ECmServiceHarvest:
       
   130             {
       
   131             error = iRepository->Get( KCmHarvesterState, state ) ;
       
   132             break;
       
   133             }
       
   134         case ECmServiceFill:
       
   135             {
       
   136             error = iRepository->Get( KCmFillState, state ) ;
       
   137             break;
       
   138             }
       
   139         case ECmServiceStore:
       
   140             {
       
   141             error = iRepository->Get( KCmStoreState, state ) ;
       
   142             break;
       
   143             }
       
   144         case ECmServiceMemoryManager:
       
   145             {
       
   146             error = iRepository->Get( KCmMemoryManagerState, state ) ;
       
   147             break;
       
   148             }
       
   149         default:
       
   150             {
       
   151             LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::GetServiceState \
       
   152             service not found"));
       
   153             error = KErrNotFound;
       
   154             break;
       
   155             }
       
   156         }
       
   157 
       
   158     if ( !error )
       
   159         {
       
   160         TRACE(Print(_L("[CmSettinsEngine]\t CCmSettingsEngine::\
       
   161         GetServiceState state = %d"), state ));
       
   162         // converting the value back
       
   163         aState = (TCmServiceState) state;
       
   164         }
       
   165 
       
   166     return error;
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // Set Content Manager service state
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 TInt CCmSettingsEngine::SetServiceState(
       
   174                                 const TCmService aService,
       
   175                                 const TCmServiceState aState )
       
   176     {
       
   177     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::SetServiceState"));
       
   178 
       
   179     TInt error( KErrNone );
       
   180 
       
   181     switch ( aService )
       
   182         {
       
   183         case ECmServiceContentManager:
       
   184             {
       
   185             error = iRepository->Set( KCmContentManagerState, (TInt)aState ) ;
       
   186             break;
       
   187             }
       
   188         case ECmServiceHarvest:
       
   189             {
       
   190             error = iRepository->Set( KCmHarvesterState, (TInt)aState ) ;
       
   191             break;
       
   192             }
       
   193         case ECmServiceFill:
       
   194             {
       
   195             error = iRepository->Set( KCmFillState, (TInt)aState ) ;
       
   196             break;
       
   197             }
       
   198         case ECmServiceStore:
       
   199             {
       
   200             error = iRepository->Set( KCmStoreState, (TInt)aState ) ;
       
   201             break;
       
   202             }
       
   203         case ECmServiceMemoryManager:
       
   204             {
       
   205             error = iRepository->Set( KCmMemoryManagerState, (TInt)aState ) ;
       
   206             break;
       
   207             }
       
   208         default:
       
   209             {
       
   210             error = KErrNotFound;
       
   211             break;
       
   212             }
       
   213         }
       
   214 
       
   215     return error;
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // Gets IAP information from Home Network's cenrep key
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 TInt CCmSettingsEngine::GetIapL( TInt& aIap ) const
       
   223     {
       
   224     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::GetIapL"));
       
   225 
       
   226 #ifdef __SERIES60_31__
       
   227     CUpnpNetworkAccess* access = CUpnpNetworkAccess::NewL( KCRUidUPnPStack );
       
   228     TInt error( access->Get( CUpnpNetworkAccess::KUPnPStackIapId, aIap ) );
       
   229     delete access;
       
   230 #else
       
   231     CUPnPSettingsEngine* settings = CUPnPSettingsEngine::NewLC();
       
   232     TInt error( settings->GetAccessPoint( aIap ) );
       
   233     CleanupStack::PopAndDestroy( settings );
       
   234 #endif
       
   235     return error;
       
   236     }
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // Gets next start time information for specified service
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 TInt CCmSettingsEngine::GetNextRuntime( const TCmService aService,
       
   243                                                  TTime& aRuntime ) const
       
   244     {
       
   245     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::GetNextRuntime"));
       
   246 
       
   247     TBuf<KTimeLength> time;
       
   248     TPtrC timePtr( time );
       
   249     TInt error( KErrNone );
       
   250 
       
   251     if ( aService == ECmServiceStore )
       
   252         {
       
   253         error = iRepository->Get( KCmNextStoreTime, time );
       
   254         }
       
   255     else // ECmServiceFill
       
   256         {
       
   257         error = iRepository->Get( KCmNextFillTime, time );
       
   258         }
       
   259 
       
   260     if ( !error )
       
   261         {
       
   262         // convert string to TInt64
       
   263         TInt64 timeInt;
       
   264         TLex lex( timePtr );
       
   265         lex.Val( timeInt );
       
   266         aRuntime = timeInt;
       
   267         }
       
   268 
       
   269     return error;
       
   270     }
       
   271 
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // Sets next start time information for specified service
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 TInt CCmSettingsEngine::SetNextRuntime( const TCmService aService,
       
   278                                                  const TTime aNextTime )
       
   279     {
       
   280     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::SetNextRuntime"));
       
   281 
       
   282     TInt error( KErrNone );
       
   283     TBuf<KTimeLength> nextRunTime;
       
   284     nextRunTime.AppendNum( aNextTime.Int64() );
       
   285 
       
   286     if (aService == ECmServiceStore)
       
   287         {
       
   288         error = iRepository->Set( KCmNextStoreTime, nextRunTime );
       
   289         }
       
   290     else // ECmServiceFill
       
   291         {
       
   292         error = iRepository->Set( KCmNextFillTime, nextRunTime ) ;
       
   293         }
       
   294 
       
   295     return error;
       
   296     }
       
   297 
       
   298 // ---------------------------------------------------------------------------
       
   299 // Gets discovery delay.
       
   300 // ---------------------------------------------------------------------------
       
   301 //
       
   302 TInt CCmSettingsEngine::GetDiscoveryDelay( TInt& aDelay ) const
       
   303     {
       
   304     TInt error( KErrNone );
       
   305     
       
   306     error = iRepository->Get( KCmDiscoveryDelay, aDelay );
       
   307     TRACE(Print(_L("[CmSettinsEngine]\t CCmSettingsEngine::\
       
   308     GetDiscoveryDelay delay = %d"), aDelay));
       
   309     
       
   310     return error;
       
   311     }
       
   312 
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // Sets discovery delay
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 TInt CCmSettingsEngine::SetDiscoveryDelay( const TInt aDelay )
       
   319     {
       
   320     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::SetDiscoveryDelay"));
       
   321 
       
   322     return iRepository->Set( KCmDiscoveryDelay, aDelay );
       
   323     }
       
   324 
       
   325 // ---------------------------------------------------------------------------
       
   326 //
       
   327 // ---------------------------------------------------------------------------
       
   328 //
       
   329 TInt CCmSettingsEngine::GetAutoSync( TBool& aAutoSync ) const
       
   330     {
       
   331     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::GetAutoSync"));
       
   332 
       
   333     TInt error( KErrNotFound );
       
   334 
       
   335     TInt autoSyncInt;
       
   336     error = iRepository->Get( KCmAutoSync, autoSyncInt );
       
   337 
       
   338     aAutoSync = (TBool) autoSyncInt;
       
   339     return error;
       
   340     }
       
   341 
       
   342 // ---------------------------------------------------------------------------
       
   343 // Sets synchronization state
       
   344 // ---------------------------------------------------------------------------
       
   345 //
       
   346 TInt CCmSettingsEngine::SetAutoSync( const TBool aAutoSync )
       
   347     {
       
   348     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::SetAutoSync"));
       
   349 
       
   350     return iRepository->Set( KCmAutoSync, (TInt)aAutoSync ) ;
       
   351     }
       
   352 
       
   353 // ---------------------------------------------------------------------------
       
   354 // Gets memory manager's status
       
   355 // ---------------------------------------------------------------------------
       
   356 //
       
   357 TInt CCmSettingsEngine::GetMemoryManagerStatus(
       
   358     TBool& aMmStatus ) const
       
   359     {
       
   360     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::GetMemoryManagerStatus"));
       
   361 
       
   362     TInt mmInt;
       
   363 
       
   364     TInt error = iRepository->Get( KCmMemoryManagerState, mmInt );
       
   365 
       
   366     if ( !error )
       
   367         {
       
   368         aMmStatus = (TBool) mmInt;
       
   369         }
       
   370 
       
   371     return error;
       
   372     }
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 // Sets memory manager's status
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 TInt CCmSettingsEngine::SetMemoryManagerStatus(
       
   379     const TBool aMmStatus )
       
   380     {
       
   381     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::SetMemoryManagerStatus"));
       
   382 
       
   383     return iRepository->Set( KCmMemoryManagerState, (TInt)aMmStatus ) ;
       
   384     }
       
   385 
       
   386 // ---------------------------------------------------------------------------
       
   387 // Gets item count for search action
       
   388 // ---------------------------------------------------------------------------
       
   389 //
       
   390 TInt CCmSettingsEngine::GetSearchCount( TInt& aItemCount ) const
       
   391     {
       
   392     TInt error( KErrNone );
       
   393     error = iRepository->Get( KCmSearchCount, aItemCount );
       
   394     TRACE(Print(_L("[CmSettinsEngine]\t CCmSettingsEngine::\
       
   395     GetSearchCount count = %d"), aItemCount));
       
   396     
       
   397     return error;
       
   398     }
       
   399 
       
   400 // ---------------------------------------------------------------------------
       
   401 // Gets item count for database add operation
       
   402 // ---------------------------------------------------------------------------
       
   403 //
       
   404 TInt CCmSettingsEngine::GetAddCount( TInt& aAddCount ) const
       
   405     {
       
   406     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::GetAddCount"));
       
   407 
       
   408     return iRepository->Get( KCmAddCount, aAddCount );
       
   409     }
       
   410 
       
   411 
       
   412 // ---------------------------------------------------------------------------
       
   413 // Gets app wizard execution status info.
       
   414 // ---------------------------------------------------------------------------
       
   415 //
       
   416 TInt CCmSettingsEngine::GetAppWizardInformation(
       
   417     TInt& aAppWizardState ) const
       
   418     {
       
   419     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::\
       
   420     GetAppWizardInformation"));
       
   421 
       
   422     return iRepository->Get( KCmAppWizardState, aAppWizardState );
       
   423     }
       
   424 
       
   425 // ---------------------------------------------------------------------------
       
   426 // Sets app wizard execution status info.
       
   427 // ---------------------------------------------------------------------------
       
   428 //
       
   429 TInt CCmSettingsEngine::SetAppWizardInformation()
       
   430     {
       
   431     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::\
       
   432     SetAppWizardInformation"));
       
   433 
       
   434 
       
   435     // application wizard run -> set status 1
       
   436     return iRepository->Set( KCmAppWizardState, 1 ) ;
       
   437     }
       
   438 
       
   439 
       
   440 // ---------------------------------------------------------------------------
       
   441 // Gets information about MCs drives
       
   442 // ---------------------------------------------------------------------------
       
   443 //
       
   444 void CCmSettingsEngine::DriveListL(
       
   445     RFs& aFs,
       
   446     RPointerArray<CCmDriveInfo>& aDrives ) const
       
   447     {
       
   448     LOG(_L("[CmSettinsEngine]\t CCmSettingsEngine::DriveListL"));
       
   449 
       
   450 
       
   451     TDriveList list;
       
   452     TDriveInfo info;
       
   453 
       
   454     aFs.DriveList( list );
       
   455     
       
   456     TInt drive( KErrNotFound );                                                         
       
   457     TInt error = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage,
       
   458                                              drive );
       
   459     TRACE( Print(_L("[CmSettinsEngine]\t GetDefaultDrive error = %d, drive = %d"),
       
   460     error, drive ) );
       
   461 
       
   462     
       
   463     for( TInt driveNumber = 0 ; driveNumber <= EDriveZ ; driveNumber++ )
       
   464         {
       
   465         if( list[driveNumber] ) // is drive available
       
   466             {
       
   467             TUint drvStatus( 0 );
       
   468             aFs.Drive( info, driveNumber );
       
   469             
       
   470             TRACE( Print(_L("[CmSettinsEngine]\t drivenumber = %d"),
       
   471                       driveNumber ) );
       
   472             User::LeaveIfError(DriveInfo::GetDriveStatus( aFs,
       
   473                                                           driveNumber,
       
   474                                                           drvStatus ) );                                                                      
       
   475                                                           
       
   476             TRACE( Print(_L("[CmSettinsEngine]\t removable drive = %d"),
       
   477                       drvStatus & DriveInfo::EDriveRemovable ) );
       
   478 
       
   479             TInt removableStatus = drvStatus & DriveInfo::EDriveRemovable;
       
   480             // Check if drive is internal hard disc or memory card
       
   481             if( 
       
   482                 ((!error && driveNumber == drive ) && !removableStatus ) ||
       
   483                 ( removableStatus && ( info.iType != EMediaNotPresent ) ) )
       
   484                 {
       
   485 
       
   486                 TRACE( Print(_L("[CmSettinsEngine]\t info.iType = %d"),
       
   487                        info.iType ) );
       
   488                 TRACE( Print(_L("[CmSettinsEngine]\t info.iDriveAtt = %d"),
       
   489                        info.iDriveAtt ) );                       
       
   490 
       
   491                 HBufC* memoryCardName = NULL;
       
   492                 CCmDriveInfo* driveInfo = CCmDriveInfo::NewLC();
       
   493                 TVolumeInfo volInfo;
       
   494                 aFs.Volume( volInfo, driveNumber );
       
   495 
       
   496                 TRACE( Print(_L("[CmSettinsEngine]\t volInfo.iName = %S"),
       
   497                        &volInfo.iName ) );
       
   498 
       
   499                 if ( volInfo.iName.Compare( KNullDesC() ) )
       
   500                     {
       
   501                     memoryCardName = volInfo.iName.AllocLC();
       
   502                     driveInfo->SetDriveNameL( *memoryCardName );
       
   503                     }
       
   504                 else
       
   505                     {
       
   506                     driveInfo->SetDriveNameL( KNullDesC() );
       
   507                     }
       
   508                 // collect drive information
       
   509                 driveInfo->SetDriveNumber( driveNumber );
       
   510                 driveInfo->SetDriveType( removableStatus );
       
   511                 driveInfo->SetDriveSize( volInfo.iSize );
       
   512                 driveInfo->SetDriveId( volInfo.iUniqueID );
       
   513 
       
   514                 aDrives.AppendL( driveInfo );
       
   515 
       
   516                 if ( memoryCardName )
       
   517                     {
       
   518                     CleanupStack::PopAndDestroy( memoryCardName );
       
   519                     }
       
   520                 CleanupStack::Pop( driveInfo );
       
   521                 }
       
   522             }
       
   523         }
       
   524     }
       
   525 
       
   526 // ---------------------------------------------------------------------------
       
   527 // Deletes the object
       
   528 // ---------------------------------------------------------------------------
       
   529 //
       
   530 void CCmSettingsEngine::Close()
       
   531     {
       
   532     delete this;
       
   533 	}
       
   534 	
       
   535 // End of file