genericservices/taskscheduler/Test/TSUtils/TPropertyDefine.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32base.h>
       
    17 #include <e32property.h>
       
    18 #include <numberconversion.h>
       
    19 #include <swi/swispubsubdefs.h>
       
    20 
       
    21 using namespace Swi;
       
    22 
       
    23 _LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames
       
    24 
       
    25 	
       
    26 //This function defines a P&S variable as requested by the parameters
       
    27 static TInt CreateVariableL(TUid aCategory, TInt aKey, TInt aAttr)
       
    28 	{
       
    29 	TSecurityPolicy readPolicy = TSecurityPolicy::EAlwaysPass;
       
    30 	TSecurityPolicy writePolicy = TSecurityPolicy::EAlwaysPass;
       
    31 	
       
    32 	TInt err = RProperty::Define(aCategory, aKey, aAttr, readPolicy, writePolicy);
       
    33 	
       
    34 	if(err != KErrAlreadyExists)
       
    35 		{
       
    36 		//This will leave for any value other than KErrNone
       
    37 		User::LeaveIfError(err);	
       
    38 		}
       
    39 		
       
    40 	//If the variable is already defined then return KErrNone as this is fine,
       
    41 	return KErrNone;
       
    42 	}
       
    43 
       
    44 GLDEF_C TInt E32Main()
       
    45     {
       
    46     	
       
    47     CTrapCleanup* cleanup = CTrapCleanup::New(); 
       
    48 	
       
    49 	TDigitType digitType;
       
    50 	TInt length;
       
    51 	TBuf<32> args;
       
    52 	User::CommandLine(args);
       
    53 	TInt error;
       
    54 	
       
    55 	TInt pos = args.Find(KSeparator);
       
    56 	
       
    57 	if(pos > 0)
       
    58 		{
       
    59 		TInt32 category = NumberConversion::ConvertFirstNumber(args.Mid(0,pos), length, digitType);
       
    60 		TUid categoryUid = TUid::Uid(category);
       
    61 		TPtrC remainder = args.Mid(pos+1, args.Length()-(pos+1));
       
    62 		pos = remainder.Find(KSeparator);
       
    63 		TUint key = NumberConversion::ConvertFirstNumber(remainder.Mid(0,pos), length, digitType);
       
    64 		TInt attr =	NumberConversion::ConvertFirstNumber(
       
    65 			remainder.Mid(pos+1, remainder.Length()-(pos+1)), length, digitType
       
    66 			);
       
    67 		
       
    68 		//create the appropriate variable
       
    69 		error = CreateVariableL(categoryUid, key, attr);			
       
    70 		}
       
    71 		
       
    72 	else error = pos;
       
    73 
       
    74 	delete cleanup;
       
    75 	return error;	
       
    76     	
       
    77 	}