omadm/dcmo/dcmoadapters/extmemctrl/src/extmemctrldcmoadapter.cpp
changeset 0 3ce708148e4d
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2009 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:  ExtMemCtrl plug-in adapter for DCMO
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <f32file.h> 
       
    20 #include <driveinfo.h>
       
    21 #include <barsread.h> 
       
    22 #include <barsc2.h>
       
    23 #include <dcmo.rsg>
       
    24 #include <stringresourcereader.h> 
       
    25 #include <f32file.h> 
       
    26 #include <data_caging_path_literals.hrh>
       
    27 #include <DevManInternalCRKeys.h>
       
    28 #include <centralrepository.h>
       
    29 #include "extmemctrldcmoadapter.h"
       
    30 
       
    31 _LIT( KExtMemCtrlProperty, "ExternalMemory");
       
    32 _LIT( KExtMemCtrlDescription, "Used to enable/disable the ExtMem");
       
    33 _LIT( KRuntimeResourceFileName, "z:dcmo.rsc" );	
       
    34 
       
    35 // Construction and destruction functions
       
    36 
       
    37 // ----------------------------------------------------------------------------------------
       
    38 // CExtMemCtrlDCMOAdapter::NewL
       
    39 // ----------------------------------------------------------------------------------------
       
    40 CExtMemCtrlDCMOAdapter* CExtMemCtrlDCMOAdapter::NewL(TAny* aParams)
       
    41 	{
       
    42 		CExtMemCtrlDCMOAdapter* self=new(ELeave) CExtMemCtrlDCMOAdapter(aParams);  
       
    43 		CleanupStack::PushL(self);
       
    44 		self->ConstructL(); 
       
    45 		CleanupStack::Pop();
       
    46 		return self;
       
    47 	}
       
    48 
       
    49 // ----------------------------------------------------------------------------------------
       
    50 // CExtMemCtrlDCMOAdapter::~CExtMemCtrlDCMOAdapter
       
    51 // ----------------------------------------------------------------------------------------
       
    52 CExtMemCtrlDCMOAdapter::~CExtMemCtrlDCMOAdapter()
       
    53 	{
       
    54 		delete iProperty;
       
    55 		iProperty = NULL;
       
    56 		delete iDescription;
       
    57 		iDescription = NULL;
       
    58 	}
       
    59 
       
    60 // ----------------------------------------------------------------------------------------
       
    61 // CExtMemCtrlDCMOAdapter::CExtMemCtrlDCMOAdapter
       
    62 // ----------------------------------------------------------------------------------------
       
    63 CExtMemCtrlDCMOAdapter::CExtMemCtrlDCMOAdapter(TAny* aInitParams)
       
    64 :  iInitParams((CDCMOInterface::TDCMOInterfaceInitParams*)aInitParams)
       
    65 	{
       
    66 	// See ConstructL() for initialisation completion.
       
    67 	}
       
    68 
       
    69 // ----------------------------------------------------------------------------------------
       
    70 // CExtMemCtrlDCMOAdapter::ConstructL
       
    71 // ----------------------------------------------------------------------------------------
       
    72 void CExtMemCtrlDCMOAdapter::ConstructL()
       
    73 {	
       
    74 	// Safely complete the initialization of the constructed object	
       
    75 	if(iInitParams->descriptor)
       
    76 		iProperty =  (iInitParams->descriptor)->AllocL();
       
    77 	else
       
    78 		iProperty = KExtMemCtrlProperty().AllocL();
       
    79 	iDescription = KExtMemCtrlDescription().AllocL();
       
    80 }
       
    81 
       
    82 // Implementation of CDCMOInterface
       
    83 
       
    84 // ----------------------------------------------------------------------------------------
       
    85 // CExtMemCtrlDCMOAdapter::GetDCMOPluginIntAttributeValueL
       
    86 // Gets the integer attribute value.
       
    87 // ----------------------------------------------------------------------------------------
       
    88 TDCMOStatus  CExtMemCtrlDCMOAdapter::GetDCMOPluginIntAttributeValueL(TDCMONode aId, TInt& aValue)
       
    89 {
       
    90 	TDCMOStatus status(EDcmoSuccess);
       
    91 	TInt err(KErrNone);
       
    92 	
       
    93 	switch(aId)
       
    94 	{
       
    95 		case EGroup: {
       
    96 									aValue = EHardware;
       
    97 								}
       
    98 						break;		
       
    99 		case EAttached:	{
       
   100 						aValue = 0;
       
   101 						RFs fsMemoryCard;
       
   102                   		err = fsMemoryCard.Connect();
       
   103                   		if ( err != KErrNone )
       
   104                   		{
       
   105                   			status = EDcmoFail;
       
   106                   		}
       
   107                   		TDriveInfo dInfo;
       
   108 						TVolumeInfo vInfo;
       
   109     					TInt error = fsMemoryCard.Drive( dInfo, EDriveF );
       
   110      					if( error == KErrNone )
       
   111          				{
       
   112          					error = fsMemoryCard.Volume( vInfo, EDriveF );
       
   113          					if( error == KErrNone )
       
   114              				{
       
   115              					aValue = 1;
       
   116              				}
       
   117          				}										
       
   118 						fsMemoryCard.Close();  
       
   119 						}
       
   120 						break;
       
   121 		case EEnabled:{
       
   122 			            RFs fsMemoryCard;
       
   123                   err = fsMemoryCard.Connect();
       
   124                   if ( err != KErrNone )
       
   125                   {
       
   126                   	status = EDcmoFail;
       
   127                   }
       
   128                       
       
   129                   TDriveInfo  info;
       
   130                   err=fsMemoryCard.Drive(info, EDriveF);
       
   131  //               DBG_ARGS8( _S8("ExtMem err =  %d info.iType = %d"), err, info.iType );
       
   132                                        
       
   133                   if (info.iType == EMediaNotPresent || err != KErrNone ||info.iType == EMediaUnknown )
       
   134                   {
       
   135                     aValue = 0;
       
   136                   }
       
   137                   else
       
   138                   { 
       
   139                     aValue = 1;
       
   140                   }                        
       
   141                   fsMemoryCard.Close();          
       
   142             		  }
       
   143 						break;		
       
   144 		case EDenyUserEnable:	{
       
   145 										aValue = 1;
       
   146 									}
       
   147 						break;
       
   148 		case ENotifyUser:	{
       
   149 											aValue = 1;
       
   150 											}
       
   151 						break;	
       
   152 		default :
       
   153 						status = 	EDcmoNotFound;		
       
   154 	}	
       
   155 	return status;
       
   156 }
       
   157 
       
   158 // ----------------------------------------------------------------------------------------
       
   159 // CExtMemCtrlDCMOAdapter::GetDCMOPluginStrAttributeValueL
       
   160 // Gets the string attribute value.
       
   161 // ----------------------------------------------------------------------------------------
       
   162 TDCMOStatus  CExtMemCtrlDCMOAdapter::GetDCMOPluginStrAttributeValueL(TDCMONode aId, TDes& aStrValue) 
       
   163 {
       
   164 	TDCMOStatus status(EDcmoSuccess);		
       
   165 	switch(aId)
       
   166 	{
       
   167 		case EProperty: 	aStrValue = *iProperty;
       
   168 							break;		
       
   169 		case EDescription:	aStrValue = *iDescription;
       
   170 							break;
       
   171 		default :	
       
   172 						status = EDcmoNotFound;	
       
   173 	}
       
   174 	return status;
       
   175 }
       
   176 
       
   177 // ----------------------------------------------------------------------------------------
       
   178 // CExtMemCtrlDCMOAdapter::SetDCMOPluginIntAttributeValueL
       
   179 // Sets the integer attribute value.
       
   180 // ----------------------------------------------------------------------------------------
       
   181 TDCMOStatus  CExtMemCtrlDCMOAdapter::SetDCMOPluginIntAttributeValueL(TDCMONode aId, TInt aValue)
       
   182 {
       
   183 	TDCMOStatus status(EDcmoFail);
       
   184 	TInt err(KErrNone);
       
   185 	
       
   186 	switch(aId)
       
   187 	{
       
   188 		case EDenyUserEnable:
       
   189 							break;
       
   190 		case ENotifyUser:
       
   191 							break;
       
   192 		case EEnable:	{
       
   193 			        			RFs fsMemoryCard;
       
   194               			err = fsMemoryCard.Connect();
       
   195               			if ( err != KErrNone )
       
   196                			{
       
   197                 		  return status ;
       
   198                			}
       
   199                			TBuf<255> fsysname;
       
   200                			fsysname.Zero();
       
   201                			if (!aValue)
       
   202                			{               	
       
   203                 			fsMemoryCard.FileSystemName(fsysname,EDriveF);
       
   204                 			TRequestStatus stat;
       
   205                 			fsMemoryCard.NotifyDismount(EDriveF, stat, EFsDismountForceDismount);
       
   206                 			User::WaitForRequest(stat);
       
   207                			 	//err= fsMemoryCard.DismountFileSystem(fsysname, EDriveF);
       
   208                 			//if (err == KErrNone)
       
   209                    		status =EDcmoSuccess;                   
       
   210                			}
       
   211                			else
       
   212                			{
       
   213                	 			TInt err(fsMemoryCard.FileSystemName(fsysname,EDriveF));
       
   214                	 			if (err != KErrNone && !fsysname.Length()) 
       
   215                	 			{
       
   216                	 				_LIT( KFmgrFatFSName, "Fat" );
       
   217                	  			err = fsMemoryCard.MountFileSystem( KFmgrFatFSName, EDriveF );
       
   218                	 			} 
       
   219                    		status = EDcmoSuccess;                                 	
       
   220                			} 
       
   221                			fsMemoryCard.Close();
       
   222 			          		CRepository *rep = NULL;
       
   223 		            		TRAPD( err1, rep = CRepository::NewL( KCRUidDeviceManagementInternalKeys )) ;
       
   224 		            		if(!err1) 
       
   225 		              		rep->Set( KDevManMemCardCtrl, aValue ); 		              
       
   226 		              	delete rep;
       
   227 		              	rep = NULL; 							
       
   228 		              }
       
   229 						break;
       
   230 		default :
       
   231 							status = EDcmoNotFound;
       
   232 	}	
       
   233 	return status;
       
   234 }
       
   235 
       
   236 // ----------------------------------------------------------------------------------------
       
   237 // CExtMemCtrlDCMOAdapter::SetDCMOPluginStrAttributeValueL
       
   238 // Sets the string attribute value.
       
   239 // ----------------------------------------------------------------------------------------
       
   240 TDCMOStatus  CExtMemCtrlDCMOAdapter::SetDCMOPluginStrAttributeValueL(TDCMONode /* aId */, const TDes& /* aStrValue */)
       
   241 {
       
   242 	// Nothing to do
       
   243 	TDCMOStatus status(EDcmoNotSupported);	
       
   244 	return status;	
       
   245 }
       
   246 
       
   247 // ----------------------------------------------------------------------------------------
       
   248 // CExtMemCtrlDCMOAdapter::GetLocalizedNameL
       
   249 // returns the localized plug-in name.
       
   250 // ----------------------------------------------------------------------------------------
       
   251 void CExtMemCtrlDCMOAdapter::GetLocalizedNameL (HBufC*& aLocName)
       
   252 {	
       
   253 	TFileName myFileName;
       
   254   TParse parseObj;
       
   255   parseObj.Set( KRuntimeResourceFileName(), &KDC_RESOURCE_FILES_DIR,NULL );
       
   256   myFileName = parseObj.FullName();
       
   257 	CStringResourceReader* test = CStringResourceReader::NewL( myFileName );
       
   258 	TPtrC buf;
       
   259 	buf.Set(test->ReadResourceString(R_DM_RUN_TIME_VAR_EXT_MEMORY)); 
       
   260 	aLocName = buf.AllocL() ; 
       
   261 	delete test;
       
   262 	test = NULL;
       
   263 }