serviceproviders/sapi_mediamanagement/tsrc/testing/performance/s60_perf/src/mgpostfilter.cpp
changeset 5 989d2f495d90
child 39 1aa6688bfd6b
equal deleted inserted replaced
1:a36b1e19a461 5:989d2f495d90
       
     1 /*
       
     2 * Copyright (c) 2007-2007 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 the License "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:   It filter the media items as per the filter value sets
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <mclfitem.h>
       
    22 #include "mgpostfilter.h"
       
    23 
       
    24 const TInt32 KLargestSigned32 = 0x7fffffff;
       
    25 const TInt64 KLargestSigned64 = 0x7fffffffffffffff;
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CPostFilter::NewL
       
    29 // Returns the instance of CPostFilter.
       
    30 // -----------------------------------------------------------------------------
       
    31 CPostFilter* CPostFilter::NewL()
       
    32 	{
       
    33 
       
    34 	CPostFilter* self = new (ELeave) CPostFilter();
       
    35 	return self;
       
    36 	}
       
    37 
       
    38 
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CPostFilter::~CPostFilter
       
    42 // Destructor
       
    43 // -----------------------------------------------------------------------------
       
    44 
       
    45 CPostFilter::~CPostFilter()
       
    46 	{
       
    47 	      delete iFilterVal;
       
    48 	}
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CPostFilter::FilterItemsL
       
    52 // Method to filter source list. This method is called when
       
    53 // the filtering process is executed by list model refresh method.
       
    54 // -----------------------------------------------------------------------------
       
    55 void CPostFilter::FilterItemsL( const TArray<MCLFItem*>& aItemList,
       
    56                                 RPointerArray<MCLFItem>& aFilteredItemList )
       
    57     {
       
    58 	// It will filter the Items
       
    59 	MCLFItem* item = NULL;
       
    60 
       
    61     for( TInt i = 0 ; i < aItemList.Count() ; ++i )
       
    62         {
       
    63         item = aItemList[i];
       
    64 
       
    65         if( 0 == CompareItem( item ))
       
    66             {
       
    67             // item should be include in result
       
    68             aFilteredItemList.AppendL( item );
       
    69             }
       
    70         }
       
    71 	}
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CPostFilter::SetFilterMetaData
       
    75 // method to set the filter metadata
       
    76 // -----------------------------------------------------------------------------
       
    77 void CPostFilter::SetFilterMetaData(const TCLFDefaultFieldId& aMetaDataId,
       
    78 									const TCLFItemDataType& aMetaDataType)
       
    79 	{
       
    80 	iFilterMetaData = aMetaDataId;
       
    81     iFilterDataType = aMetaDataType;
       
    82  	}
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CPostFilter::SetFilterValue
       
    86 // Method to set the filter value
       
    87 // return KErrCancel if the FilterMetaData is not Set
       
    88 // return KErrArgument if the Start or End Value is not Supported
       
    89 // return KErrNone if sucessful
       
    90 // -----------------------------------------------------------------------------
       
    91 void CPostFilter::SetFilterValueL(const TDesC& aStartVal,
       
    92 								  const TDesC& aEndVal)
       
    93 	{
       
    94 	// check the filter values as per the meta data ...
       
    95 	// If any abnormal values come it will return proper error code..
       
    96 	switch ( iFilterDataType )
       
    97         {
       
    98         case ECLFItemDataTypeDesC:
       
    99             {
       
   100             //Filter Id and Value Not NULL
       
   101             if( 0 != aStartVal.CompareF( KNullDesC ) )
       
   102                	{
       
   103             	iFilterVal = aStartVal.AllocL();
       
   104             	}
       
   105             else
       
   106                 {
       
   107                 User::Leave( KErrArgument );
       
   108                 }
       
   109             break;
       
   110             }
       
   111 
       
   112         case ECLFItemDataTypeTTime:
       
   113 	        {
       
   114 	        if( ( 0 == aStartVal.CompareF( KNullDesC ) ) &&
       
   115 	        ( 0 == aEndVal.CompareF( KNullDesC ) ) )
       
   116 	            {
       
   117 	        	User::Leave( KErrArgument );
       
   118 	            }
       
   119 	        if( 0 != aStartVal.CompareF( KNullDesC ) )
       
   120     			{
       
   121     			// check whether start time is in correct format
       
   122 	            if( KErrNone != iStartTime.Set( aStartVal ) )
       
   123 	            	{
       
   124 	            	User::Leave( KErrArgument );
       
   125 	            	}
       
   126 	            }
       
   127 
       
   128 	        if( 0 != aEndVal.CompareF( KNullDesC ) )
       
   129 	            {
       
   130 	            // check whether end time is in correct format
       
   131 	            if( KErrNone != iEndTime.Set( aEndVal ) )
       
   132 	                {
       
   133 	            	User::Leave( KErrArgument );
       
   134 	            	}
       
   135 	            }
       
   136 
       
   137 	        if( iStartTime > iEndTime )
       
   138 	            {
       
   139 	        	User::Leave( KErrArgument );
       
   140 	            }
       
   141 
       
   142 	        break;
       
   143 	        }
       
   144 
       
   145 	    case ECLFItemDataTypeTInt32:
       
   146 	        {
       
   147 	        TLex lex;
       
   148 	        if( ( 0 == aStartVal.CompareF( KNullDesC ) ) &&
       
   149 	        ( 0 == aEndVal.CompareF( KNullDesC ) ) )
       
   150 	            {
       
   151 	        	User::Leave( KErrArgument );
       
   152 	            }
       
   153 	        if( 0 != aStartVal.CompareF( KNullDesC ) )
       
   154     			{
       
   155     			lex = aStartVal;
       
   156     			//check if start value was valid
       
   157 	            if( KErrNone != lex.Val( iStartIntVal ) )
       
   158 	                {
       
   159 	            	User::Leave( KErrArgument );
       
   160 	            	}
       
   161     			}
       
   162 
       
   163 	        if( 0 != aEndVal.CompareF( KNullDesC ) )
       
   164             	{
       
   165             	lex = aEndVal;
       
   166             	//check if end value given was valid
       
   167 	            if( KErrNone != lex.Val( iEndIntVal ) )
       
   168 	               	{
       
   169             	    User::Leave( KErrArgument );
       
   170             		}
       
   171             	}
       
   172             	
       
   173             if( iStartIntVal > iEndIntVal 
       
   174             	|| iStartIntVal<0 
       
   175             	|| iEndIntVal<0)
       
   176 	        	{
       
   177        	        User::Leave( KErrArgument );
       
   178             	}
       
   179 
       
   180 	        break;
       
   181 	        }
       
   182 
       
   183 	   default:
       
   184 	        {
       
   185 	       	User::Leave( KErrArgument );
       
   186 	        }
       
   187        	}//End Switch Case
       
   188        
       
   189     }// End Function
       
   190 
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CPostFilter::CPostFilter
       
   194 // Constructor
       
   195 // -----------------------------------------------------------------------------
       
   196 CPostFilter::CPostFilter():
       
   197              iFilterMetaData( ECLFFieldIdNull ),
       
   198 		     iFilterVal(NULL),
       
   199 			 iStartTime( 0 ),
       
   200 			 iEndTime( KLargestSigned64 ),
       
   201 			 iStartIntVal( 0 ),
       
   202 			 iEndIntVal( KLargestSigned32 )
       
   203 	{
       
   204 
       
   205 	}
       
   206 
       
   207 
       
   208 
       
   209 
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CPostFilter::Clear
       
   213 // It will clear  the filter metadata field
       
   214 // -----------------------------------------------------------------------------
       
   215 void CPostFilter::Clear()
       
   216 	{
       
   217 	 iFilterMetaData = ECLFFieldIdNull;
       
   218 	 iFilterDataType = ECLFItemDataTypeNull;
       
   219 	 iStartIntVal=0;
       
   220 	 iEndIntVal =KLargestSigned32;
       
   221 	 iStartTime = 0;
       
   222 	 iEndTime =KLargestSigned64;
       
   223 
       
   224 
       
   225 	 delete iFilterVal;
       
   226 	 iFilterVal = NULL;
       
   227 
       
   228 	}
       
   229 
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CPostFilter::CompareItem
       
   233 // This function will check if the given aItem matches with the set
       
   234 // filtered values or not.
       
   235 // @return -1 If aItem does not match with the set filter values ,0 If it match.
       
   236 // -----------------------------------------------------------------------------
       
   237 TInt CPostFilter::CompareItem( MCLFItem*  aItem )
       
   238 	{
       
   239 	 //this function matches the aItem with the filter values.
       
   240      TInt retValue = 0;
       
   241 	 // If no filter MetaData skip the function
       
   242 	 if( ECLFFieldIdNull !=  iFilterMetaData  )
       
   243 	 {
       
   244 	 switch ( iFilterDataType )
       
   245     	{
       
   246        	case ECLFItemDataTypeDesC:
       
   247        		{
       
   248             if( 0 != ( *iFilterVal ).CompareF( KNullDesC ) )
       
   249     			{
       
   250 		        TPtrC itemVal;
       
   251 	            if( KErrNone == aItem->GetField( iFilterMetaData, itemVal ) )
       
   252 	            	{
       
   253 	            	if( 0 != itemVal.CompareF( *iFilterVal ) )
       
   254 	            		{
       
   255 	            		retValue = -1;
       
   256 	            		}
       
   257 	            	}
       
   258 	            else
       
   259 	            	{
       
   260 	            	retValue = -1;
       
   261 	            	}
       
   262 		        }
       
   263 		    break;
       
   264          	}// case ECLFItemDataTypeDesC
       
   265 
       
   266 
       
   267       	case ECLFItemDataTypeTTime:
       
   268 	        {
       
   269 	        TTime itemVal;
       
   270 	        if( KErrNone == aItem->GetField( iFilterMetaData, itemVal ) )
       
   271 	        	{
       
   272 	            if( !(( itemVal >= iStartTime ) && ( itemVal <= iEndTime )) )
       
   273 	                {
       
   274 	            	retValue = -1;
       
   275 	                }
       
   276 	            	
       
   277 	            }
       
   278 	        else
       
   279 	         	{
       
   280 	            retValue = -1;
       
   281 	         	}
       
   282             break;
       
   283 	        }// case ECLFItemDataTypeTTime
       
   284 
       
   285 
       
   286 	    case ECLFItemDataTypeTInt32:
       
   287 	    	{
       
   288          	TInt32 itemVal;
       
   289 	       	if( KErrNone == aItem->GetField( iFilterMetaData, itemVal ) )
       
   290 	       		{
       
   291 	        	if( !(( itemVal >= iStartIntVal ) && ( itemVal <= iEndIntVal )))
       
   292 	        	    {
       
   293 	        	    retValue = -1;
       
   294 	        	    }
       
   295             	}
       
   296 	        else
       
   297 	        	{
       
   298 	            retValue = -1;
       
   299 	        	}
       
   300 	        break;
       
   301 	        }// case ECLFItemDataTypeTInt32
       
   302 
       
   303 	    default:
       
   304 	        {
       
   305 	       	retValue = -1;
       
   306 	       	break;
       
   307             }
       
   308         
       
   309         }//End Switch Case
       
   310 	 }
       
   311     return retValue;
       
   312 	}
       
   313 
       
   314