1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/Test/TSUtils/TPropertyDefine.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,77 @@
1.4 +// Copyright (c) 2006-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 <numberconversion.h>
1.22 +#include <swi/swispubsubdefs.h>
1.23 +
1.24 +using namespace Swi;
1.25 +
1.26 +_LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames
1.27 +
1.28 +
1.29 +//This function defines a P&S variable as requested by the parameters
1.30 +static TInt CreateVariableL(TUid aCategory, TInt aKey, TInt aAttr)
1.31 + {
1.32 + TSecurityPolicy readPolicy = TSecurityPolicy::EAlwaysPass;
1.33 + TSecurityPolicy writePolicy = TSecurityPolicy::EAlwaysPass;
1.34 +
1.35 + TInt err = RProperty::Define(aCategory, aKey, aAttr, readPolicy, writePolicy);
1.36 +
1.37 + if(err != KErrAlreadyExists)
1.38 + {
1.39 + //This will leave for any value other than KErrNone
1.40 + User::LeaveIfError(err);
1.41 + }
1.42 +
1.43 + //If the variable is already defined then return KErrNone as this is fine,
1.44 + return KErrNone;
1.45 + }
1.46 +
1.47 +GLDEF_C TInt E32Main()
1.48 + {
1.49 +
1.50 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.51 +
1.52 + TDigitType digitType;
1.53 + TInt length;
1.54 + TBuf<32> args;
1.55 + User::CommandLine(args);
1.56 + TInt error;
1.57 +
1.58 + TInt pos = args.Find(KSeparator);
1.59 +
1.60 + if(pos > 0)
1.61 + {
1.62 + TInt32 category = NumberConversion::ConvertFirstNumber(args.Mid(0,pos), length, digitType);
1.63 + TUid categoryUid = TUid::Uid(category);
1.64 + TPtrC remainder = args.Mid(pos+1, args.Length()-(pos+1));
1.65 + pos = remainder.Find(KSeparator);
1.66 + TUint key = NumberConversion::ConvertFirstNumber(remainder.Mid(0,pos), length, digitType);
1.67 + TInt attr = NumberConversion::ConvertFirstNumber(
1.68 + remainder.Mid(pos+1, remainder.Length()-(pos+1)), length, digitType
1.69 + );
1.70 +
1.71 + //create the appropriate variable
1.72 + error = CreateVariableL(categoryUid, key, attr);
1.73 + }
1.74 +
1.75 + else error = pos;
1.76 +
1.77 + delete cleanup;
1.78 + return error;
1.79 +
1.80 + }