contextframework/cfwplugins/PSStateSourcePlugIn/src/psstatemapperint.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2006-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:  CPSStateMapperInt class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <cfcontextinterface.h>
       
    20 #include <cfcontextobject.h>
       
    21 #include <e32debug.h>
       
    22 
       
    23 #include "psstatemapperint.h"
       
    24 
       
    25 /*
       
    26 namespace
       
    27     {
       
    28     #ifdef _DEBUG
       
    29     
       
    30     // Panic category
       
    31     _LIT( KPanicCat, "PSStateMapInt" );
       
    32     
       
    33     // Panic codes
       
    34     enum TPanicReason
       
    35         {
       
    36         EInvalidConstructionParameters
       
    37         };
       
    38         
       
    39     // Local panic function
       
    40     LOCAL_C void Panic( TInt aCode )
       
    41         {
       
    42         User::Panic( KPanicCat, aCode );
       
    43         }
       
    44     
       
    45     #endif
       
    46     }
       
    47 */
       
    48 
       
    49 CPSStateMapperInt* CPSStateMapperInt::NewL(
       
    50     MCFContextInterface& aCF )
       
    51     {
       
    52     CPSStateMapperInt* self = CPSStateMapperInt::NewLC( aCF );
       
    53     CleanupStack::Pop();
       
    54     
       
    55     return self;
       
    56     }
       
    57   
       
    58 CPSStateMapperInt* CPSStateMapperInt::NewLC(
       
    59     MCFContextInterface& aCF )
       
    60     {
       
    61     CPSStateMapperInt* self = new( ELeave ) CPSStateMapperInt( aCF );
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL( );
       
    64     
       
    65     return self;
       
    66     }
       
    67   
       
    68 // Destructor
       
    69 CPSStateMapperInt::~CPSStateMapperInt()
       
    70     {
       
    71    	if(iStartCB)
       
    72 		{
       
    73 		iStartCB->Cancel();
       
    74 		delete iStartCB; iStartCB = 0;
       
    75 		}
       
    76 		
       
    77     iIntNameMappings.ResetAndDestroy();
       
    78     }
       
    79 
       
    80 CPSStateMapperInt::CPSStateMapperInt(
       
    81     MCFContextInterface& aCF ) : CPSStateMapper( aCF )
       
    82     {
       
    83     }
       
    84     
       
    85 // METHODS
       
    86 
       
    87 
       
    88 TInt CPSStateMapperInt::MapperType() const
       
    89 	{
       
    90 	return EPSIntMapper;
       
    91 	}
       
    92 
       
    93 void CPSStateMapperInt::AddMappingL(TInt aPSValue, const TDesC& aContextValue)
       
    94 	{
       
    95 	
       
    96 	CIntNamePair* mapping = CIntNamePair::NewLC(aPSValue, aContextValue );
       
    97 	iIntNameMappings.AppendL(mapping);
       
    98 	CleanupStack::Pop(); // mapping
       
    99 	}
       
   100 
       
   101 
       
   102 void CPSStateMapperInt::Define()
       
   103 	{
       
   104 	TInt err = RProperty::Define( iPSCategory,
       
   105         iPSKey,
       
   106         RProperty::EInt );
       
   107     
       
   108 #ifdef _DEBUG
       
   109     RDebug::Printf("CPSStateMapperInt::Define: iPSCategory=%08X, iPSKey=%08X, err = %d", iPSCategory.iUid, iPSKey, err);
       
   110 #endif
       
   111 
       
   112     iCF.DefineContext( *iSource,
       
   113         *iType,
       
   114         iSecurityPolicy );
       
   115 	}
       
   116 
       
   117 void CPSStateMapperInt::InitializeL()
       
   118 	{
       
   119 	User::LeaveIfError(
       
   120         iProperty.Attach( iPSCategory, iPSKey ) );
       
   121     
       
   122     iStartCB = new (ELeave) CAsyncCallBack(TCallBack(CPSStateMapperInt::StartCallback, this), EPriorityStandard);
       
   123 	iStartCB->CallBack();
       
   124 	
       
   125 	}
       
   126 
       
   127 //-----------------------------------------------------------------------------
       
   128 // CPSStateMapperInt::ProperyChangedL
       
   129 //-----------------------------------------------------------------------------
       
   130 //
       
   131 void CPSStateMapperInt::ProperyChangedL()
       
   132     {
       
   133     TBool mappingFound = EFalse;
       
   134     
       
   135     TInt psvalue = 0;
       
   136     if (iProperty.Get ( psvalue ) == KErrNone)
       
   137     	{
       
   138 #ifdef _DEBUG
       
   139     	RDebug::Printf("CPSStateMapperInt::ProperyChangedL: iPSCategory=%08X, iPSKey=%08X, val = %d", iPSCategory.iUid, iPSKey, psvalue);
       
   140 #endif
       
   141     	TInt count = iIntNameMappings.Count();
       
   142 	    for (TInt i = 0; i < count; i++)
       
   143 	    	{
       
   144 	    	if (iIntNameMappings[i]->Int() == psvalue)
       
   145 	    		{
       
   146 	    		mappingFound = ETrue;
       
   147 	    			
       
   148 	    		// Configure context object
       
   149 	            iContext->SetSourceL( *iSource );
       
   150 	            iContext->SetTypeL( *iType );
       
   151 	            iContext->SetValueL( iIntNameMappings[i]->Name() );	
       
   152 	    		
       
   153 	    		// Publish
       
   154                 RThread thread;
       
   155                 iCF.PublishContext( *iContext, thread );
       
   156                 thread.Close();
       
   157 	    		}		
       
   158 	    	}
       
   159 		
       
   160 	    if ( !mappingFound && iPassThrough )
       
   161 	    	{
       
   162 	    	// Configure context object
       
   163 	        iContext->SetSourceL( *iSource );
       
   164 	        iContext->SetTypeL( *iType );
       
   165 	
       
   166 			TBuf<10> contextValue;
       
   167 			contextValue.Zero();
       
   168 			contextValue.AppendNum(psvalue);
       
   169 	        iContext->SetValueL( contextValue );	
       
   170 			
       
   171 			// Publish
       
   172 	        RThread thread;
       
   173 	        iCF.PublishContext( *iContext, thread );
       
   174 	        thread.Close();
       
   175 	    	}
       
   176         }
       
   177     else
       
   178     	{
       
   179 
       
   180     	}
       
   181         
       
   182     }
       
   183 
       
   184 TInt CPSStateMapperInt::StartCallback(TAny* aPtr)
       
   185 	{
       
   186 	static_cast<CPSStateMapperInt*>(aPtr)->DoStart();
       
   187 	
       
   188 	return 0;
       
   189 	}
       
   190 	
       
   191 void CPSStateMapperInt::DoStart()
       
   192 	{
       
   193 	Subscribe();
       
   194     TRAP_IGNORE(ProperyChangedL());
       
   195 	}