remotestoragefw/gsplugin/src/rsfwgspropertywatch.cpp
branchRCL_3
changeset 19 88ee4cf65e19
parent 16 87c71b25c937
child 20 1aa8c82cb4cb
equal deleted inserted replaced
16:87c71b25c937 19:88ee4cf65e19
     1 /*
       
     2 * Copyright (c) 2005 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:  RsfwPlugin Implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <rsfwmountman.h>
       
    20 #include <rsfwmountentry.h>
       
    21 
       
    22 #include "rsfwgspropertywatch.h"
       
    23 //#include "rsfwgsplugin.hrh"
       
    24 #include "rsfwgsplugindrivelistcontainer.h"
       
    25 #include "rsfwcommon.h"
       
    26 
       
    27 
       
    28 CRsfwGsPropertyWatch* CRsfwGsPropertyWatch::NewL(CRsfwGsPluginDriveListContainer* aContainer) 
       
    29 	{
       
    30 	CRsfwGsPropertyWatch* me=new(ELeave) CRsfwGsPropertyWatch;
       
    31 	CleanupStack::PushL(me);
       
    32 	me->ConstructL(aContainer);
       
    33 	CleanupStack::Pop(me);
       
    34 	return me;
       
    35 	}
       
    36 
       
    37 CRsfwGsPropertyWatch::CRsfwGsPropertyWatch()
       
    38 	:CActive(EPriority)
       
    39 	{}
       
    40 	
       
    41 void CRsfwGsPropertyWatch::ConstructL(CRsfwGsPluginDriveListContainer* aContainer)
       
    42 	{
       
    43 	iContainer = aContainer;
       
    44 	User::LeaveIfError(iProperty.Attach(KRfeServerSecureUid, ERsfwPSKeyConnect));
       
    45 	CActiveScheduler::Add(this);
       
    46 	iProperty.Subscribe(iStatus);
       
    47 	SetActive();
       
    48 	}
       
    49 	
       
    50 CRsfwGsPropertyWatch::~CRsfwGsPropertyWatch()	
       
    51 	{
       
    52 	Cancel();
       
    53 	iProperty.Close();
       
    54 	}
       
    55 	
       
    56 void CRsfwGsPropertyWatch::DoCancel()
       
    57 {
       
    58 	iProperty.Cancel();
       
    59 }
       
    60 
       
    61 void CRsfwGsPropertyWatch::RunL()
       
    62 {
       
    63 	// resubscribe before processing new value to prevent missing updates
       
    64 	iProperty.Subscribe(iStatus);
       
    65 	SetActive();
       
    66 	if ((iProperty.Get(KRfeServerSecureUid, ERsfwPSKeyConnect, iDriveList) == KErrNone) &&
       
    67 	// if the key is defined but not written to, the length of the list is zero
       
    68 		(iDriveList.Length() == KMaxDrives))  
       
    69 	{
       
    70 		TDriveList fsDriveList;
       
    71 		RFs fs;
       
    72 		User::LeaveIfError(fs.Connect());
       
    73 		CleanupClosePushL(fs);
       
    74 		fs.DriveList(fsDriveList, KDriveAttRemote);		
       
    75 		TInt drive = EDriveY;
       
    76 		while (drive >=0) {
       
    77         	if (fsDriveList[drive] && (fsDriveList[drive] & KDriveAttRemote)) {
       
    78         		// get the friendly name for this drive
       
    79         		TChar driveChar;
       
    80         		fs.DriveToChar(drive, driveChar);
       
    81         		const CRsfwMountEntry* mountEntry;
       
    82         		mountEntry = iContainer->iMountMan->MountEntryL(driveChar);
       
    83         		if (!mountEntry) 
       
    84         		    {
       
    85         		    User::Leave(KErrNotFound);
       
    86         		    }
       
    87         		const HBufC* mountName;
       
    88         		mountName= mountEntry->Item(EMountEntryItemName);
       
    89         		if (!mountName) 
       
    90         		    {
       
    91         		    User::Leave(KErrNotFound);
       
    92         		    }
       
    93         		if (iDriveList[drive] == 0) 
       
    94         		{
       
    95         			 iContainer->SetDriveConnectedStateL(*mountName, EFalse);
       
    96         		}
       
    97         		else if (iDriveList[drive] == 1) 
       
    98         		{
       
    99         			iContainer->SetDriveConnectedStateL(*mountName, ETrue);	
       
   100         		}
       
   101         	}
       
   102         	drive--;	
       
   103 		}
       
   104        CleanupStack::PopAndDestroy(); // fs
       
   105 	}
       
   106 }
       
   107 
       
   108 // End of File