secureswitools/swisistools/source/interpretsislib/expressionevaluator.h
changeset 0 ba25891c3a9e
child 34 741e5bba2bd1
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006-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 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef	EXPRESSIONEVALUATOR_H
       
    20 #define	EXPRESSIONEVALUATOR_H
       
    21 
       
    22 #include "sisfile.h"
       
    23 #include "sisregistry.h"
       
    24 #include "errors.h"
       
    25 #include "sisexpression.h"
       
    26 
       
    27 // Classes referenced
       
    28 class RomManager;
       
    29 class ConfigManager;
       
    30 
       
    31 // Max recursion depth
       
    32 const static int KMaxExpressionDepth=100;
       
    33 
       
    34 /** 
       
    35 * @file EXPRESSIONEVALUATOR.H
       
    36 *
       
    37 * @internalComponent
       
    38 * @released
       
    39 */
       
    40 class ExpressionEnvironment
       
    41 	{
       
    42 public:
       
    43 	ExpressionEnvironment( const SisFile& aSisFile, 
       
    44                            const SisRegistry& aRegistry,
       
    45                            RomManager& aRomManager,
       
    46                            ConfigManager& aConfigManager,
       
    47                            const std::wstring& aCDrive );
       
    48 
       
    49 	/**
       
    50 	 * Check whether a file exists, corresponds to EXISTS() function in package
       
    51 	 * format.
       
    52 	 */
       
    53 	bool FindFile(const std::wstring& aFileName);
       
    54 
       
    55 	/**
       
    56 	 * Queries an application property, which is a key,value pair associated 
       
    57 	 * with an isntalled package. This corresponds to APPPROP() function in
       
    58 	 * package format.
       
    59 	 */
       
    60 	TUint32 ApplicationProperty(TUint32 aPackageUid, TUint32 aKey);
       
    61 
       
    62 	/**
       
    63 	 * Queries the registry to check if a package exists or not.
       
    64 	 */
       
    65 	bool Package(TUint32 aKey);
       
    66 
       
    67 	int Variable( int aVariableId );
       
    68 
       
    69 	const std::wstring GetPackageName();
       
    70 
       
    71 	/**
       
    72 	 * Queries the registry to determine whether the version of a specific
       
    73 	 * installed package satisfies the given relational condition 
       
    74 	 *
       
    75 	 * @param aArgsString	The argument string should contain the following
       
    76 	 *						comma seperated parameters:
       
    77 	 *
       
    78 	 *						-packageUid 			- 	UID of the package to check
       
    79 	 *						-relational Operator -	Comparision operator
       
    80 	 *						-vMajor				-	Major Version component
       
    81 	 *						-vMinor				-	Minor Version component
       
    82 	 *						-vBuild				-	Build Version component					
       
    83 	 *
       
    84 	 * @return				"TRUE" if the queried package version satisfies the
       
    85 	 *						condition, otherwise "FALSE".
       
    86 	 */
       
    87 	bool PackageVersion(const std::wstring& aArgsString);
       
    88 
       
    89 	/**
       
    90 	 * Check whether a languageID exists within the list device supported languages.
       
    91 	 *
       
    92 	 * @param aLanguageIdString	The Language Id to check for.
       
    93 	 * @return 					True if the language exists, False otherwise.
       
    94 	 */
       
    95 	bool DeviceLanguage(const std::wstring& aLanguageIdString);
       
    96 	
       
    97 private:
       
    98 	const SisFile& iSisFile;
       
    99 	const SisRegistry& iSisRegistry;
       
   100     RomManager& iRomManager;
       
   101     ConfigManager& iConfigManager;
       
   102 	const std::wstring& iCDrive;
       
   103 	};
       
   104 
       
   105 
       
   106 
       
   107 
       
   108 
       
   109 
       
   110 
       
   111 
       
   112 
       
   113 
       
   114 
       
   115 /**
       
   116 Implements the ExpressionResult.
       
   117 @internalComponent
       
   118 */
       
   119 class ExpressionResult
       
   120 	{
       
   121 public:
       
   122 	enum TType { EString, EInt };
       
   123 	ExpressionResult(const std::wstring& aString);
       
   124 	ExpressionResult(TUint32 aInt);
       
   125 	TUint32 IntegerValue() const;
       
   126 	bool BoolValue() const;
       
   127 	const std::wstring& StringValue() const;
       
   128 	TType Type() const { return iType; }
       
   129 
       
   130 private:
       
   131 	TType iType;
       
   132 	union
       
   133 		{
       
   134 		const std::wstring* iString;
       
   135 		TUint32 iInt;
       
   136 		};
       
   137 	};
       
   138 
       
   139 
       
   140 
       
   141 
       
   142 
       
   143 
       
   144 
       
   145 
       
   146 
       
   147 
       
   148 
       
   149 
       
   150 
       
   151 inline bool operator==( const ExpressionResult& aLhs, const ExpressionResult& aRhs )
       
   152     {
       
   153     bool result( false );
       
   154     //
       
   155 	if  ( aLhs.Type() != aRhs.Type() )
       
   156 		{
       
   157 		std::string error = "corrupt SIS file: expression corrupt in condition statement";
       
   158 		throw InvalidSis("",error,INVALID_SIS);
       
   159 		}
       
   160     else if ( aLhs.Type() == ExpressionResult::EInt )
       
   161 		{
       
   162         result = ( aLhs.IntegerValue() == aRhs.IntegerValue() );
       
   163 		}
       
   164 	else
       
   165 		{
       
   166         result = ( aLhs.StringValue() == aRhs.StringValue() );
       
   167 		}
       
   168     //
       
   169     return result;
       
   170     }
       
   171 
       
   172 
       
   173 inline ExpressionResult operator!=( const ExpressionResult& aLhs, const ExpressionResult& aRhs )
       
   174     {
       
   175     bool equal = ( aLhs == aRhs );
       
   176     const ExpressionResult result( !equal );
       
   177     return result;
       
   178     }
       
   179 
       
   180 
       
   181 inline ExpressionResult operator!( const ExpressionResult& aExpression )
       
   182     {
       
   183 	if  ( aExpression.Type() != ExpressionResult::EInt )
       
   184 		{
       
   185 		std::string error = "corrupt SIS file: expression corrupt in condition statement";
       
   186         throw InvalidSis("",error,INVALID_SIS);
       
   187 		}
       
   188     //
       
   189     return ExpressionResult(!aExpression.IntegerValue()); // Will Never Leave
       
   190     }
       
   191 
       
   192 
       
   193 inline ExpressionResult operator<( const ExpressionResult& aLhs, const ExpressionResult& aRhs )
       
   194     {
       
   195 	if  ( aLhs.Type() != aRhs.Type() || aLhs.Type() != ExpressionResult::EInt )
       
   196 		{
       
   197 		std::string error = "corrupt SIS file: expression corrupt in condition statement";
       
   198 		throw InvalidSis("",error,INVALID_SIS);
       
   199 		}
       
   200     //
       
   201     const ExpressionResult result( aLhs.IntegerValue() < aRhs.IntegerValue() );
       
   202     return result;
       
   203     }
       
   204 
       
   205 
       
   206 inline ExpressionResult operator>( const ExpressionResult& aLhs, const ExpressionResult& aRhs )
       
   207     {
       
   208 	if  ( aLhs.Type() != aRhs.Type() || aLhs.Type() != ExpressionResult::EInt )
       
   209 		{
       
   210 		std::string error = "corrupt SIS file: expression corrupt in condition statement";
       
   211 		throw InvalidSis("",error,INVALID_SIS);
       
   212 		}
       
   213     //
       
   214     const ExpressionResult result( aLhs.IntegerValue() > aRhs.IntegerValue() );
       
   215     return result;
       
   216     }
       
   217 
       
   218 
       
   219 inline ExpressionResult operator<=( const ExpressionResult& aLhs, const ExpressionResult& aRhs )
       
   220     {
       
   221 	if  ( aLhs.Type() != aRhs.Type() || aLhs.Type() != ExpressionResult::EInt )
       
   222 		{
       
   223 		std::string error = "corrupt SIS file: expression corrupt in condition statement";
       
   224 		throw InvalidSis("",error,INVALID_SIS);
       
   225 		}
       
   226     //
       
   227     const ExpressionResult result( aLhs.IntegerValue() <= aRhs.IntegerValue() );
       
   228     return result;
       
   229     }
       
   230 
       
   231 
       
   232 inline ExpressionResult operator>=( const ExpressionResult& aLhs, const ExpressionResult& aRhs )
       
   233     {
       
   234 	if  ( aLhs.Type() != aRhs.Type() || aLhs.Type() != ExpressionResult::EInt )
       
   235 		{
       
   236 		std::string error = "corrupt SIS file: expression corrupt in condition statement";
       
   237 		throw InvalidSis("",error,INVALID_SIS);
       
   238 		}
       
   239     //
       
   240     const ExpressionResult result( aLhs.IntegerValue() >= aRhs.IntegerValue() );
       
   241     return result;
       
   242     }
       
   243 
       
   244 
       
   245 
       
   246 
       
   247 
       
   248 
       
   249 
       
   250 /**
       
   251 Implements the ExpressionEvaluator.
       
   252 @internalComponent
       
   253 */
       
   254 class ExpressionEvaluator
       
   255 	{
       
   256 public:
       
   257 	ExpressionEvaluator(ExpressionEnvironment& aEnvironment);
       
   258 	void SetFile(const SisFile& aSisFile);
       
   259 	void SetRegistry(const SisRegistry& aSisRegistry);
       
   260 	
       
   261 	ExpressionResult Evaluate(const CSISExpression& aExpression);
       
   262 	ExpressionResult Evaluate(const CSISExpression* aExpression);
       
   263 
       
   264 private:
       
   265 	void Require(const void *aPointer) const;
       
   266 
       
   267 private:
       
   268 	ExpressionEnvironment& iExpEnv;
       
   269 	int iExpressionDepth;
       
   270 	ExpressionResult iTempResult;
       
   271 	};
       
   272 
       
   273 #endif	/* EXPRESSIONEVALUATOR_H */