menucontentsrv/srvsrc/mcsmmcobserver.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "mcsmmcobserver.h"
       
    20 
       
    21 _LIT(KMcsDir,"*:\\private\200113dd\\import");
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // CCMCsMmcObserver::CCMCsMmcObserver
       
    25 // ---------------------------------------------------------------------------
       
    26 //
       
    27 CMcsMmcObserver::CMcsMmcObserver(MMcsMmcObserver& aCallback) :
       
    28 	CActive(EPriorityStandard), // Standard priority
       
    29 	iCallback(aCallback)
       
    30 	{
       
    31 	CActiveScheduler::Add(this); // Add to scheduler
       
    32 	}
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // CCMCsMmcObserver::NewLC
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CMcsMmcObserver* CMcsMmcObserver::NewLC(MMcsMmcObserver& aCallback)
       
    39 	{
       
    40 	CMcsMmcObserver* self = new (ELeave) CMcsMmcObserver(aCallback);
       
    41 	CleanupStack::PushL(self);
       
    42 	self->ConstructL();
       
    43 	return self;
       
    44 	}
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CCMCsMmcObserver::NewL
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CMcsMmcObserver* CMcsMmcObserver::NewL(MMcsMmcObserver& aCallback)
       
    51 	{
       
    52 	CMcsMmcObserver* self = CMcsMmcObserver::NewLC(aCallback);
       
    53 	CleanupStack::Pop(); // self;
       
    54 	return self;
       
    55 	}
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CCMCsMmcObserver::ConstructL
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 void CMcsMmcObserver::ConstructL()
       
    62 	{
       
    63 	User::LeaveIfError( iFs.Connect( ) );
       
    64 	User::LeaveIfError(iFs.DriveList(iDriveList));
       
    65 	iDriveCount = DriveCount(iDriveList);
       
    66 	iFs.NotifyChange(ENotifyEntry, iStatus, KMcsDir);
       
    67 	SetActive();
       
    68 	}
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CCMCsMmcObserver::~CCMCsMmcObserver
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CMcsMmcObserver::~CMcsMmcObserver()
       
    75 	{
       
    76 	Cancel(); // Cancel any request, if outstanding
       
    77 	iFs.Close();
       
    78 	}
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CCMCsMmcObserver::DoCancel
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CMcsMmcObserver::DoCancel()
       
    85 	{
       
    86 	iFs.NotifyChangeCancel();
       
    87 	}
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CCMCsMmcObserver::RunL
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CMcsMmcObserver::RunL()
       
    94 	{
       
    95 	if (iStatus == KErrNone)
       
    96 		{
       
    97 		// Get driver number and compare to last state
       
    98 		User::LeaveIfError(iFs.DriveList(iDriveList));
       
    99 		TInt driveCountNow = DriveCount(iDriveList);
       
   100 		if (iDriveCount < driveCountNow)
       
   101 			{
       
   102 			iCallback.HandleMmcEventL(MMcsMmcObserver::EMmcInsert);
       
   103 			}
       
   104 		else if (iDriveCount > driveCountNow)
       
   105 			{
       
   106 			iCallback.HandleMmcEventL(MMcsMmcObserver::EMmcRemove);
       
   107 			}
       
   108 		iDriveCount = driveCountNow;
       
   109 		}
       
   110 	iFs.NotifyChange(ENotifyEntry, iStatus, KMcsDir);
       
   111 	SetActive(); // Tell scheduler a request is active
       
   112 	}
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CCMCsMmcObserver::RunError
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 TInt CMcsMmcObserver::RunError(TInt /*aError*/)
       
   119 	{
       
   120 	iFs.NotifyChange(ENotifyEntry, iStatus, KMcsDir);
       
   121 	SetActive(); // Tell scheduler a request is active
       
   122 	return KErrNone;
       
   123 	}
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CCMCsMmcObserver::DriveCount
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 TInt CMcsMmcObserver::DriveCount(TDriveList& aDriveList)
       
   130 	{
       
   131 	TInt driveCount(0);
       
   132 	TDriveInfo driveInfo;
       
   133 	
       
   134 	// Count drives
       
   135 	for (TInt driveNumber = EDriveA; driveNumber <= EDriveZ; driveNumber++)
       
   136 		{
       
   137 		if (aDriveList[driveNumber])
       
   138 			{
       
   139 			// Be sure it's not unmounted
       
   140 			iFs.Drive(driveInfo, driveNumber);
       
   141 			if (driveInfo.iType != EMediaNotPresent)
       
   142 				{
       
   143 				++driveCount;
       
   144 				}
       
   145 			}
       
   146 		}
       
   147 	return driveCount;
       
   148 	}