os/ossrv/lowlevellibsandfws/pluginfw/Framework/EcomTestUtils/TPropertyManagerSrv.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/Framework/EcomTestUtils/TPropertyManagerSrv.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,201 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <e32base.h>
1.20 +#include <e32property.h>
1.21 +#include <e32debug.h>
1.22 +#include "TPropertyManager.h"
1.23 +
1.24 +_LIT(KSeparator, "|"); // Char used to separate arguments
1.25 +
1.26 +static TInt DefineProperty(TUid aCategory, TUint aKey, TInt aAttr,TInt aPreallocated)
1.27 + {
1.28 + _LIT_SECURE_ID(mySid,0X10204FC5);
1.29 +
1.30 + TSecurityPolicy readPolicy = TSecurityPolicy::EAlwaysPass;
1.31 + TSecurityPolicy writePolicy = TSecurityPolicy(mySid);
1.32 +
1.33 + TInt err = RProperty::Define(aCategory, aKey, aAttr, readPolicy, writePolicy, aPreallocated);
1.34 +
1.35 + //If the variable is already defined then return KErrNone as this is fine,
1.36 + if(err == KErrAlreadyExists)
1.37 + {
1.38 + err = KErrNone;
1.39 + }
1.40 +
1.41 + RDebug::Print(_L("Property Manager - Define Property Cat = %d Key = %d err = %d\n"), aCategory,aKey, err);
1.42 +
1.43 + return err;
1.44 + }
1.45 +
1.46 +static TInt DeleteProperty(TUid aCategory, TUint aKey)
1.47 + {
1.48 + TInt err = RProperty::Delete(aCategory, aKey);
1.49 +
1.50 + //If the variable is not found then return KErrNone as this is fine
1.51 + if(err == KErrNotFound)
1.52 + {
1.53 + err = KErrNone;
1.54 + }
1.55 +
1.56 + RDebug::Print(_L("Property Manager - Delete Property Cat = %d Key = %d err = %d\n"), aCategory,aKey, err);
1.57 +
1.58 + return err;
1.59 + }
1.60 +
1.61 +static TInt SetProperty(TUid aCategory, TUint aKey, TInt aValue)
1.62 + {
1.63 + TInt err = RProperty::Set(aCategory, aKey, aValue);
1.64 + RDebug::Print(_L("Property Manager - Set Property Cat = %d Key = %d Value = %d err = %d\n"), aCategory,aKey,aValue,err);
1.65 + return err;
1.66 + }
1.67 +
1.68 +static TInt SetProperty(TUid aCategory, TUint aKey, const TDesC8 &aValue)
1.69 + {
1.70 + TInt err = RProperty::Set(aCategory, aKey, aValue);
1.71 + RDebug::Print(_L("Property Manager - Set Property Cat = %d Key = %d Value = %S err = %d\n"), aCategory,aKey,&aValue,err);
1.72 + return err;
1.73 + }
1.74 +
1.75 +static TInt SetProperty(TUid aCategory, TUint aKey, const TDesC16 &aValue)
1.76 + {
1.77 + TInt err = RProperty::Set(aCategory, aKey, aValue);
1.78 + RDebug::Print(_L("Property Manager - Set Property Cat = %d Key = %d Value = %S err = %d\n"), aCategory,aKey,&aValue,err);
1.79 + return err;
1.80 + }
1.81 +
1.82 +TInt GetNumber(const TPtrC& aText, TInt& aLength)
1.83 + {
1.84 + TInt total = 0;
1.85 + aLength = 0;
1.86 + TInt textLength = aText.Length();
1.87 +
1.88 + //Loop through each character and verify that it is a valid digit
1.89 + //before converting to a decimal representation and adding to the total
1.90 + while (aLength < textLength)
1.91 + {
1.92 + TChar currentChar = aText[aLength];
1.93 + if (currentChar < '0' || currentChar > '9')
1.94 + {
1.95 + return total;
1.96 + }
1.97 +
1.98 + TInt digit = 0;
1.99 + TUint charValue = currentChar;
1.100 +
1.101 + //Convert from character value to decimal
1.102 + digit = charValue - 0x30; //(offset for western digit characters
1.103 + total = (total * 10) + digit;
1.104 + aLength++;
1.105 + }
1.106 + return total;
1.107 + }
1.108 +
1.109 +static TInt ParseArgs(TDesC& aArgs, TInt& aStartIndex)
1.110 + {
1.111 + TInt length;
1.112 + TInt value;
1.113 +
1.114 + //Get a substrng of aArgs begining at aStartIndex
1.115 + TPtrC string = aArgs.Mid(aStartIndex,aArgs.Length() - aStartIndex);
1.116 +
1.117 + //Find the position of the first separator
1.118 + TInt pos = string.Find(KSeparator);
1.119 +
1.120 + if(pos > 0)
1.121 + {
1.122 + //Get the number that exists in the substring before the separator
1.123 + value = GetNumber(string.Mid(0,pos),length);
1.124 + }
1.125 + //If a separator is not found, then this must be the last number in aArgs
1.126 + else
1.127 + {
1.128 + value = GetNumber(string,length);
1.129 + }
1.130 +
1.131 + //Update the start index to the character following the separator
1.132 + aStartIndex += (pos +1);
1.133 +
1.134 + return value;
1.135 + }
1.136 +
1.137 +static TInt ProcessCommandLine(TDesC& aArgs)
1.138 + {
1.139 + TInt error;
1.140 + TInt pos = 0;
1.141 + TInt length = aArgs.Length();
1.142 +
1.143 + //Pull out the common elements of all commands - Op, Cat & Key
1.144 + PropertyManager::TOperation operation = PropertyManager::TOperation(ParseArgs(aArgs,pos));
1.145 + TInt category = ParseArgs(aArgs,pos);
1.146 + TUid categoryUid = TUid::Uid(category);
1.147 + TUint key = ParseArgs(aArgs,pos);
1.148 +
1.149 + TInt attr;
1.150 + TInt preallocated;
1.151 + TInt intVal;
1.152 + TBuf8<64> value;
1.153 +
1.154 + //Handle each operation separately to pull out the remaining arguments
1.155 + //and process the request.
1.156 + switch(operation)
1.157 + {
1.158 + case PropertyManager::EDefineProperty:
1.159 + attr = ParseArgs(aArgs,pos);
1.160 + preallocated = ParseArgs(aArgs,pos);
1.161 + error = DefineProperty(categoryUid,key,attr,preallocated);
1.162 + break;
1.163 +
1.164 + case PropertyManager::EDeleteProperty:
1.165 + error = DeleteProperty(categoryUid,key);
1.166 + break;
1.167 +
1.168 + case PropertyManager::ESetPropertyInt:
1.169 + intVal = ParseArgs(aArgs,pos);
1.170 + error = SetProperty(categoryUid,key,intVal);
1.171 + break;
1.172 +
1.173 + case PropertyManager::ESetPropertyDes8:
1.174 + value.Copy(aArgs.Mid(pos,(aArgs.Length()-pos)));
1.175 + error = SetProperty(categoryUid,key,value);
1.176 + break;
1.177 +
1.178 + case PropertyManager::ESetPropertyDes16:
1.179 + error = SetProperty(categoryUid,key,aArgs.Mid(pos,(aArgs.Length()-pos)));
1.180 + break;
1.181 +
1.182 + default:
1.183 + error = KErrArgument;
1.184 + break;
1.185 + }
1.186 +
1.187 + return error;
1.188 + }
1.189 +
1.190 +GLDEF_C TInt E32Main()
1.191 + {
1.192 +
1.193 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.194 +
1.195 + TBuf<64> args;
1.196 + User::CommandLine(args);
1.197 +
1.198 + TInt error = ProcessCommandLine(args);
1.199 +
1.200 + delete cleanup;
1.201 + return error;
1.202 +
1.203 + }
1.204 +