sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #include <e32base.h>
sl@0: #include <e32property.h>
sl@0: #include <numberconversion.h>
sl@0: #include <swi/swispubsubdefs.h>
sl@0: 
sl@0: using namespace Swi;
sl@0: 
sl@0: _LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames
sl@0: 
sl@0: 	
sl@0: //This function defines a P&S variable as requested by the parameters
sl@0: static TInt CreateVariableL(TUid aCategory, TInt aKey, TInt aAttr)
sl@0: 	{
sl@0: 	TSecurityPolicy readPolicy = TSecurityPolicy::EAlwaysPass;
sl@0: 	TSecurityPolicy writePolicy = TSecurityPolicy::EAlwaysPass;
sl@0: 	
sl@0: 	TInt err = RProperty::Define(aCategory, aKey, aAttr, readPolicy, writePolicy);
sl@0: 	
sl@0: 	if(err != KErrAlreadyExists)
sl@0: 		{
sl@0: 		//This will leave for any value other than KErrNone
sl@0: 		User::LeaveIfError(err);	
sl@0: 		}
sl@0: 		
sl@0: 	//If the variable is already defined then return KErrNone as this is fine,
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: GLDEF_C TInt E32Main()
sl@0:     {
sl@0:     	
sl@0:     CTrapCleanup* cleanup = CTrapCleanup::New(); 
sl@0: 	
sl@0: 	TDigitType digitType;
sl@0: 	TInt length;
sl@0: 	TBuf<32> args;
sl@0: 	User::CommandLine(args);
sl@0: 	TInt error;
sl@0: 	
sl@0: 	TInt pos = args.Find(KSeparator);
sl@0: 	
sl@0: 	if(pos > 0)
sl@0: 		{
sl@0: 		TInt32 category = NumberConversion::ConvertFirstNumber(args.Mid(0,pos), length, digitType);
sl@0: 		TUid categoryUid = TUid::Uid(category);
sl@0: 		TPtrC remainder = args.Mid(pos+1, args.Length()-(pos+1));
sl@0: 		pos = remainder.Find(KSeparator);
sl@0: 		TUint key = NumberConversion::ConvertFirstNumber(remainder.Mid(0,pos), length, digitType);
sl@0: 		TInt attr =	NumberConversion::ConvertFirstNumber(
sl@0: 			remainder.Mid(pos+1, remainder.Length()-(pos+1)), length, digitType
sl@0: 			);
sl@0: 		
sl@0: 		//create the appropriate variable
sl@0: 		error = CreateVariableL(categoryUid, key, attr);			
sl@0: 		}
sl@0: 		
sl@0: 	else error = pos;
sl@0: 
sl@0: 	delete cleanup;
sl@0: 	return error;	
sl@0:     	
sl@0: 	}