sysstatemgmt/systemstatereferenceplugins/custcmd/src/ssmuiproviderdlldefault.cpp
changeset 16 ef634fd8dac3
parent 0 4e1aa6a622a0
child 41 c87e5f80c17d
--- a/sysstatemgmt/systemstatereferenceplugins/custcmd/src/ssmuiproviderdlldefault.cpp	Fri Apr 16 16:18:45 2010 +0300
+++ b/sysstatemgmt/systemstatereferenceplugins/custcmd/src/ssmuiproviderdlldefault.cpp	Mon May 03 13:42:22 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -21,7 +21,7 @@
 #include "ssmuiproviderdll.h"
 #include "ssmpanic.h"
 #include <e32property.h>
-#include <f32file.h>
+#include "ssmdebug.h"
 
 const TUid KPSStartupUid = {0x2000E65E};
 const TUid KSecurityPinNotifierUid = {0x2000E667};
@@ -37,17 +37,20 @@
 const TUint KRFStatusPropertyKey = 0x2001D2A9;
 const TUid KValidateRTCPropertyCategory = {0x2000D75B};
 const TUint KValidateRTCPropertyKey = 0x2001D2AB;
+//Number of clusterSize to be reserve for phone memory space 
+const TInt KNumberOfCluster = 2;
 
 _LIT(KTsyModuleName, "mm.tsy");
 _LIT(KTsyPhoneName, "GsmPhone1");
 
 CSsmUiSpecific::CSsmUiSpecific()
-: iReferenceCount(1)
+: iReferenceCount(1), iReservedPhoneMemory(0)
 	{
 	}
 
 EXPORT_C CSsmUiSpecific::~CSsmUiSpecific()
 	{
+	iReservedPhoneMemoryFs.Close();
 	}
 
 EXPORT_C TUid CSsmUiSpecific::StartupPSUid()
@@ -95,7 +98,7 @@
 		//Instantiate CSsmUiSpecific if TLS is null
 		self = new (ELeave) CSsmUiSpecific();
 		CleanupStack::PushL(self);
-		
+		self->ConstructL();
 		//Copy CSsmUiSpecific pointer in TLS
 		User::LeaveIfError(Dll::SetTls(self));
 		CleanupStack::Pop(self);
@@ -203,3 +206,73 @@
 	return EDriveC;
 	}
 
+/**
+Leaving construction inside ConstructL
+*/
+void CSsmUiSpecific::ConstructL()
+	{
+	User::LeaveIfError( iReservedPhoneMemoryFs.Connect() );
+	}
+
+/**
+Reserve two ClusterSize in Phone Memory Space on H/W
+and 512 bytes for __WINS__
+@return KErrNone if successful or systemwide error
+*/
+EXPORT_C TInt CSsmUiSpecific::ReservePhoneMemorySpace()
+    {
+	TVolumeIOParamInfo volumeParamInfo; 
+	const TInt phoneMemoryDriveID = PhoneMemoryRootDriveId();
+	TInt errorCode = iReservedPhoneMemoryFs.VolumeIOParam(phoneMemoryDriveID, volumeParamInfo); 
+	if( KErrNone == errorCode )
+		{
+#ifdef __WINS__
+		//512 bytes for __WINS__
+		const TInt reservedMemory = 512;
+#else
+		//Reserving two clusterSize Phone memory 
+		const TInt reservedMemory = KNumberOfCluster * (volumeParamInfo.iClusterSize);
+#endif //__WINS__
+		errorCode = iReservedPhoneMemoryFs.ReserveDriveSpace(phoneMemoryDriveID, reservedMemory);
+
+		if ( KErrNone == errorCode )
+			{
+			iReservedPhoneMemory = reservedMemory;
+			}
+		}
+    return errorCode;
+    }
+
+/**
+Free reserved bytes from Phone Memory Space. If aSpaceToFree is 0 bytes 
+then free complete reserved memory
+@param aSpaceToFree request to free memory
+@return KErrNone if successful or systemwide error
+*/
+EXPORT_C TInt CSsmUiSpecific::FreeReservedPhoneMemorySpace(const TInt aSpaceToFree)
+    {
+    TInt errorCode(KErrGeneral);
+	DEBUGPRINT3A("Reserved memory is = %d bytes, Request to free memory is = %d bytes", iReservedPhoneMemory, aSpaceToFree);
+    if(0 < iReservedPhoneMemory)
+        {
+		if(0 == aSpaceToFree)
+		    {
+		   	//Free complete reserved phone memory
+			errorCode = iReservedPhoneMemoryFs.ReserveDriveSpace( PhoneMemoryRootDriveId(), 0 );
+			DEBUGPRINT2A("Freeing memory completed with = %d", errorCode);
+			iReservedPhoneMemory = 0; 
+		    }
+		else
+		    {
+		    TInt newReserveSize = iReservedPhoneMemory - aSpaceToFree;
+		    newReserveSize = newReserveSize >= 0 ? newReserveSize : 0;
+		    errorCode = iReservedPhoneMemoryFs.ReserveDriveSpace( PhoneMemoryRootDriveId(), newReserveSize );
+			DEBUGPRINT2A("Freeing partial phone memory completed with = %d", errorCode);
+		    if(KErrNone == errorCode)
+			    {
+			    iReservedPhoneMemory = newReserveSize;
+			    }
+		    }
+    	}
+    return errorCode;
+    }