omadm/omadmextensions/adapters/wlanctrldcmoadapter/src/wlanctrldcmoadapter.cpp
changeset 1 4490afcb47b1
equal deleted inserted replaced
0:3ce708148e4d 1:4490afcb47b1
       
     1 /*
       
     2  * ==============================================================================
       
     3  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     4  * All rights reserved.
       
     5  * This component and the accompanying materials are made available
       
     6  * under the terms of "Eclipse Public License v1.0"
       
     7  * which accompanies this distribution, and is available
       
     8  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9  *
       
    10  * Initial Contributors:
       
    11  * Nokia Corporation - initial contribution.
       
    12  *
       
    13  * Contributors:
       
    14  * 
       
    15  * Description:
       
    16  * 
       
    17  * ==============================================================================
       
    18  */
       
    19 
       
    20 #include <featurecontrol.h>
       
    21 #include <featmgr.h>
       
    22 #include <stringresourcereader.h>
       
    23 #include <data_caging_path_literals.hrh> 
       
    24 #include <bautils.h>
       
    25 
       
    26 #include <dcmo.rsg>
       
    27 
       
    28 #include "wlanctrldcmoadapter.h"
       
    29 
       
    30 _LIT( KWlanCtrlProperty, "WLAN" );
       
    31 _LIT( KDisableWlanDescription, "Used to enable/disable the WLAN connectivity." ); // Description
       
    32 _LIT( KRuntimeResourceFileName, "z:dcmo.rsc" );
       
    33 
       
    34 TDCMOStatus CWLanCtrlDCMOAdapter::MapFeatureControlError( TInt aErrorCode )
       
    35     {
       
    36     TDCMOStatus status( EDcmoFail );
       
    37     
       
    38     switch ( aErrorCode )
       
    39         {
       
    40         case KErrNone:
       
    41             status = EDcmoSuccess;
       
    42             break;
       
    43         case KErrPermissionDenied:
       
    44         case KErrAccessDenied:
       
    45             status = EDcmoAccessDenied;
       
    46             break;
       
    47         case KErrNotFound:
       
    48             status = EDcmoNotFound;
       
    49             break;
       
    50         default:
       
    51             break;
       
    52         }
       
    53     return status;
       
    54     }
       
    55 
       
    56 // Construction and destruction functions
       
    57 
       
    58 CWLanCtrlDCMOAdapter* CWLanCtrlDCMOAdapter::NewL( TAny* aParams )
       
    59 	{
       
    60 	CWLanCtrlDCMOAdapter* self = new ( ELeave ) CWLanCtrlDCMOAdapter( aParams );  
       
    61 	CleanupStack::PushL( self );
       
    62 	self->ConstructL(); 
       
    63 	CleanupStack::Pop();
       
    64 	return self;
       
    65 	}
       
    66 
       
    67 CWLanCtrlDCMOAdapter::~CWLanCtrlDCMOAdapter()
       
    68 	{	
       
    69 	FeatureManager::UnInitializeLib();
       
    70 	
       
    71 	delete iProperty;
       
    72 	delete iDescription;
       
    73 	}
       
    74 
       
    75 CWLanCtrlDCMOAdapter::CWLanCtrlDCMOAdapter( TAny* aInitParams )
       
    76 :  iInitParams( ( CDCMOInterface::TDCMOInterfaceInitParams* ) aInitParams )
       
    77 	{
       
    78 	// See ConstructL() for initialisation completion.
       
    79 	}
       
    80 
       
    81 void CWLanCtrlDCMOAdapter::ConstructL()
       
    82 	{	
       
    83 	// Set up the data to pass back
       
    84 	iProperty = KWlanCtrlProperty().AllocL();
       
    85 	iDescription = KDisableWlanDescription().AllocL();
       
    86 	
       
    87     FeatureManager::InitializeLibL();
       
    88 
       
    89 	}
       
    90 
       
    91 
       
    92 // Implementation of CDCMOInterface
       
    93 TDCMOStatus CWLanCtrlDCMOAdapter::SetDCMOPluginIntAttributeValueL(TDCMONode aId, TInt aValue)
       
    94 {
       
    95 	TDCMOStatus status(EDcmoFail);
       
    96 	TInt err( KErrNone );
       
    97 	
       
    98 	switch( aId )
       
    99 	{
       
   100 		case EDenyUserEnable:
       
   101 		    status = EDcmoNotSupported;
       
   102 		    break;
       
   103 		case ENotifyUser:
       
   104 		    status = EDcmoNotSupported;
       
   105 			break;
       
   106 		case EEnable:	
       
   107 		    {
       
   108             RFeatureControl featureControl;
       
   109             TUid wlanUid( TUid::Uid( KFeatureIdProtocolWlan ) ); 
       
   110             err = featureControl.Connect();
       
   111             
       
   112             if ( err == KErrNone )
       
   113                 {
       
   114                 if( aValue == 0 )
       
   115                     {
       
   116                     // Disable WLAN
       
   117                     err = featureControl.DisableFeature( wlanUid );
       
   118 		            }
       
   119                 else if ( aValue == 1 )
       
   120                     {
       
   121                     // Enable WLAN
       
   122                     err = featureControl.EnableFeature( wlanUid );
       
   123                     }
       
   124                 status = MapFeatureControlError( err );
       
   125                 featureControl.Close();
       
   126                 }
       
   127             
       
   128 		    }
       
   129 		    break;
       
   130 		default:
       
   131 		    break;
       
   132 	}
       
   133 	
       
   134 	return status;
       
   135 }
       
   136 
       
   137 TDCMOStatus CWLanCtrlDCMOAdapter::GetDCMOPluginIntAttributeValueL(TDCMONode aId, TInt& aValue)
       
   138 {
       
   139 	TDCMOStatus status( EDcmoSuccess );
       
   140 	
       
   141 	switch(aId)
       
   142 	{
       
   143 		case EGroup: 
       
   144 		    aValue = EConnectivity;
       
   145 		    break;
       
   146 		case EAttached:
       
   147 		    aValue = EFalse;
       
   148 		    break;
       
   149 		case EEnabled:	
       
   150 		    aValue = FeatureManager::FeatureSupported( KFeatureIdProtocolWlan );		    
       
   151 		    break;    
       
   152 		case EDenyUserEnable:
       
   153 		    aValue = EFalse;
       
   154 		    break; 
       
   155 		case ENotifyUser:
       
   156 		    aValue = ETrue;
       
   157 		    break;
       
   158 		case EEnable:
       
   159 		    status = EDcmoAccessDenied;
       
   160 		    break;
       
   161 		default:
       
   162 		    break;
       
   163 	}
       
   164 	
       
   165 	return status;
       
   166 }
       
   167 
       
   168 TDCMOStatus CWLanCtrlDCMOAdapter::SetDCMOPluginStrAttributeValueL( TDCMONode   /* aId */, 
       
   169                                                                    const TDes& /* aStrValue */ )
       
   170 {
       
   171 	// Nothing to do
       
   172 	TDCMOStatus status( EDcmoFail );
       
   173 	
       
   174 	return status;	
       
   175 }
       
   176 
       
   177 TDCMOStatus CWLanCtrlDCMOAdapter::GetDCMOPluginStrAttributeValueL( TDCMONode aId, TDes& aStrValue ) 
       
   178 {
       
   179 	TDCMOStatus status( EDcmoSuccess );
       
   180 	switch( aId )
       
   181 	{
       
   182 		case EProperty: 	
       
   183 		    aStrValue = *iProperty;
       
   184 		    break;
       
   185 		case EDescription:	
       
   186 		    aStrValue = *iDescription;
       
   187 		    break;
       
   188 		default:			
       
   189 		    status = EDcmoNotFound;
       
   190 		    break;
       
   191 	}
       
   192 		
       
   193 	return status;
       
   194 }
       
   195 
       
   196 void CWLanCtrlDCMOAdapter::GetLocalizedNameL( HBufC*& aLocName )
       
   197     {
       
   198     TFileName myFileName;
       
   199     TParse* parseObj = new(ELeave) TParse();
       
   200     TInt errInt = parseObj->Set( KRuntimeResourceFileName(), &KDC_RESOURCE_FILES_DIR, NULL );
       
   201     myFileName = parseObj->FullName();
       
   202     delete parseObj;
       
   203     CStringResourceReader* resReader = CStringResourceReader::NewL( myFileName );
       
   204     TPtrC buf;
       
   205     buf.Set(resReader->ReadResourceString(R_DM_RUN_TIME_VAR_WLAN)); 
       
   206     aLocName = buf.AllocL() ; 
       
   207     delete resReader;
       
   208     }