upnpmediaserver/mediaserverengine/src/upnpdiskremovedetector.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /** @file
       
     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:  Detects remove disk event.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "upnpdiskremovedetector.h"
       
    21 #include "upnpmediaserver.h"
       
    22 #include "upnpcontentdirectoryglobals.h"
       
    23 #include <f32file.h>
       
    24 
       
    25 #ifdef _DEBUG
       
    26 #define KLogFile _L("UPnPMediaServer.txt")
       
    27 #endif
       
    28 #include "upnpcustomlog.h"
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CUpnpDiskRemoveDetector::CUpnpDiskRemoveDetector
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CUpnpDiskRemoveDetector::CUpnpDiskRemoveDetector( CUpnpMediaServer* aObserver ) :
       
    39     CActive( CActive::EPriorityStandard ), iObserver( aObserver )
       
    40     {
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CUpnpDiskRemoveDetector::ConstructL
       
    45 // Symbian 2nd phase constructor can leave.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void CUpnpDiskRemoveDetector::ConstructL()
       
    49     {
       
    50     User::LeaveIfError( iFs.Connect() );
       
    51     CActiveScheduler::Add( this );
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CUpnpDiskRemoveDetector::NewLC
       
    56 // Two-phased constructor.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CUpnpDiskRemoveDetector* CUpnpDiskRemoveDetector::NewLC(
       
    60     CUpnpMediaServer* aObserver )
       
    61     {
       
    62     CUpnpDiskRemoveDetector* self =
       
    63     	new (ELeave) CUpnpDiskRemoveDetector( aObserver );
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL();
       
    66     return self;
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CUpnpDiskRemoveDetector::NewL
       
    71 // Two-phased constructor.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CUpnpDiskRemoveDetector* CUpnpDiskRemoveDetector::NewL(
       
    75     CUpnpMediaServer* aObserver )
       
    76     {
       
    77     CUpnpDiskRemoveDetector* self =
       
    78             CUpnpDiskRemoveDetector::NewLC( aObserver );
       
    79     CleanupStack::Pop( self );
       
    80     return self;
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CUpnpDiskRemoveDetector::~CUpnpDiskRemoveDetector
       
    85 // Destructor
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 CUpnpDiskRemoveDetector::~CUpnpDiskRemoveDetector()
       
    89     {
       
    90     Cancel();
       
    91     iFs.Close();
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CUpnpDiskRemoveDetector::Start
       
    96 // Enable object to watch for incoming events.
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CUpnpDiskRemoveDetector::StartL()
       
   100     {
       
   101     if ( !IsActive() )
       
   102         {
       
   103         // we want to check the validity of upload directory on MS startup
       
   104         CheckUploadDirectoryL();
       
   105         SubscribeForDiskEvent();
       
   106         }
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // CUpnpDiskRemoveDetector::CheckUploadDirectoryL
       
   111 // Check if the upload direcotory is valid.
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CUpnpDiskRemoveDetector::CheckUploadDirectoryL()
       
   115     {
       
   116     // Getting current upload directory from cenrep
       
   117     CUpnpMediaServerSettings* settings = CUpnpMediaServerSettings::NewL();
       
   118     CleanupStack::PushL( settings );
       
   119 
       
   120     HBufC8* uploadtmp = settings->GetL( UpnpMediaServerSettings::EUploadDirectory );
       
   121     CleanupStack::PushL( uploadtmp );
       
   122 
       
   123     HBufC* uploaddir = HBufC::NewLC( uploadtmp->Length() );
       
   124     uploaddir->Des().Copy( *uploadtmp );
       
   125 
       
   126     // retrieving drive info
       
   127     TParse path;
       
   128     path.Set( uploaddir->Des(), NULL, NULL );
       
   129     TDriveUnit driveUnit( path.Drive() );
       
   130 
       
   131     TVolumeInfo volumeInfo;
       
   132     volumeInfo.iDrive.iType = EMediaNotPresent;
       
   133     TInt err = iFs.Volume( volumeInfo, static_cast<TInt>( driveUnit ) );
       
   134 
       
   135     if ( err != KErrNone )
       
   136         {
       
   137         TChar systemDriveLetter;
       
   138         TInt error = RFs::DriveToChar( RFs::GetSystemDrive(), systemDriveLetter );
       
   139 
       
   140         RBuf tmpUploadDir;
       
   141         tmpUploadDir.CleanupClosePushL();
       
   142         tmpUploadDir.CreateL( KCharLen
       
   143                             + KCol().Length()
       
   144                             + KDiskPathElSep().Length()
       
   145                             + KDefaultUploadDir().Length() );
       
   146 
       
   147         tmpUploadDir.Append( systemDriveLetter );
       
   148         tmpUploadDir.Append( KCol() );
       
   149         tmpUploadDir.Append( KDiskPathElSep() );
       
   150         tmpUploadDir.Append( KDefaultUploadDir() );
       
   151         iObserver->SetUploadDirL( tmpUploadDir );
       
   152         CleanupStack::PopAndDestroy( &tmpUploadDir );
       
   153         }
       
   154     else
       
   155         {
       
   156         LOGS( "CUpnpDiskRemoveDetector - some disk was dismounted, but it's not interesting in that context" );
       
   157         }
       
   158 
       
   159     CleanupStack::PopAndDestroy( uploaddir );
       
   160     CleanupStack::PopAndDestroy( uploadtmp );
       
   161     CleanupStack::PopAndDestroy( settings );
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // CUpnpDiskRemoveDetector::SubscribeForDiskEvent
       
   166 // Subscribe this object for file system disk event
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 void CUpnpDiskRemoveDetector::SubscribeForDiskEvent()
       
   170     {
       
   171     // wait for FileSystem disk event (like MMC card removal)
       
   172     if ( !IsActive() )
       
   173         {
       
   174         iFs.NotifyChange( ENotifyDisk, iStatus );
       
   175         SetActive();
       
   176         }
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // CUpnpDiskRemoveDetector::RunL
       
   181 // Called after event occurs or on media server startup
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 void CUpnpDiskRemoveDetector::RunL()
       
   185     {
       
   186     User::LeaveIfError( iStatus.Int() );
       
   187     CheckUploadDirectoryL();
       
   188     SubscribeForDiskEvent();
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CUpnpDiskRemoveDetector::RunError
       
   193 // RunError is called when RunL leaves.
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 TInt CUpnpDiskRemoveDetector::RunError( TInt aError )
       
   197     {
       
   198     LOGS1( "CUpnpDiskRemoveDetector::RunError(%d)", aError );
       
   199     SubscribeForDiskEvent();
       
   200     return KErrNone;
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CUpnpDiskRemoveDetector::DoCancel
       
   205 // Cancel watching for incoming events.
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 void CUpnpDiskRemoveDetector::DoCancel()
       
   209     {
       
   210     iFs.NotifyChangeCancel();
       
   211     }
       
   212 
       
   213 // End of File