sl@0: // Copyright (c) 2007-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 sl@0: #include sl@0: #include sl@0: #include sl@0: #include "TPropertyManager.h" sl@0: sl@0: _LIT(KSeparator, "|"); // Char used to separate arguments sl@0: _LIT(KPropertyManagerSrvName,"TPropertyManagerSrv"); sl@0: _LIT(KPropertyManagerPanic,"TPropertyManager::SetProperty"); sl@0: sl@0: TInt PropertyManager::LaunchHelperProcess(TOperation aOperation,TDesC& aArgs) sl@0: { sl@0: TBuf<64> args; sl@0: args.AppendNum(aOperation); sl@0: args.Append(KSeparator); sl@0: args.Append(aArgs); sl@0: sl@0: // Property Manager Srv uid sl@0: const TUid KSystemAgentExeUid = {0x10204FC5}; sl@0: const TUidType serverUid(KNullUid, KNullUid, KSystemAgentExeUid); sl@0: RProcess server; sl@0: TInt err = server.Create(KPropertyManagerSrvName, args, serverUid); sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Print(_L("Error Launching Property Manager...")); sl@0: return err; sl@0: } sl@0: sl@0: RDebug::Print(_L("Property Manager Launched...")); sl@0: TRequestStatus stat; sl@0: server.Rendezvous(stat); sl@0: if(stat != KRequestPending) sl@0: { sl@0: server.Kill(0); // abort startup sl@0: } sl@0: else sl@0: { sl@0: server.Resume(); // logon OK - start the server sl@0: } sl@0: User::WaitForRequest(stat); // wait for start or death sl@0: // we can't use the 'exit reason' if the server panicked as this sl@0: // is the panic 'reason' and may be '0' which cannot be distinguished sl@0: // from KErrNone sl@0: err = server.ExitType() == EExitPanic ? KErrGeneral : stat.Int(); sl@0: server.Close(); sl@0: sl@0: RDebug::Print(_L("Property Manager Terminated...")); sl@0: return err; sl@0: sl@0: } sl@0: sl@0: EXPORT_C TInt PropertyManager::DefineProperty(TUid aCategory, TUint aKey, TInt aAttr,TInt aPreallocated) sl@0: { sl@0: TBuf<64> args; sl@0: args.AppendNum(aCategory.iUid); sl@0: args.Append(KSeparator); sl@0: args.AppendNum(aKey); sl@0: args.Append(KSeparator); sl@0: args.AppendNum(aAttr); sl@0: args.Append(KSeparator); sl@0: args.AppendNum(aPreallocated); sl@0: sl@0: return LaunchHelperProcess(EDefineProperty,args); sl@0: } sl@0: sl@0: EXPORT_C TInt PropertyManager::DeleteProperty(TUid aCategory, TUint aKey) sl@0: { sl@0: TBuf<64> args; sl@0: args.AppendNum(aCategory.iUid); sl@0: args.Append(KSeparator); sl@0: args.AppendNum(aKey); sl@0: sl@0: return LaunchHelperProcess(EDeleteProperty,args); sl@0: } sl@0: sl@0: EXPORT_C TInt PropertyManager::SetProperty(TUid aCategory, TUint aKey, TInt aValue) sl@0: { sl@0: TBuf<64> args; sl@0: args.AppendNum(aCategory.iUid); sl@0: args.Append(KSeparator); sl@0: args.AppendNum(aKey); sl@0: args.Append(KSeparator); sl@0: args.AppendNum(aValue); sl@0: sl@0: return LaunchHelperProcess(ESetPropertyInt,args); sl@0: } sl@0: sl@0: EXPORT_C TInt PropertyManager::SetProperty(TUid aCategory, TUint aKey, const TDesC8 &aValue) sl@0: { sl@0: TBuf<64> args; sl@0: args.AppendNum(aCategory.iUid); sl@0: args.Append(KSeparator); sl@0: args.AppendNum(aKey); sl@0: args.Append(KSeparator); sl@0: sl@0: //Need to check maximum length of this field.... sl@0: if((args.Size() + aValue.Size()) > args.MaxSize()) sl@0: { sl@0: User::Panic(KPropertyManagerPanic,0); sl@0: } sl@0: sl@0: //Convert the 8Bit descriptor into a 16 bit version sl@0: TBuf<128> value; sl@0: value.Copy(aValue); sl@0: args.Append(value); sl@0: sl@0: return LaunchHelperProcess(ESetPropertyDes8,args); sl@0: } sl@0: sl@0: EXPORT_C TInt PropertyManager::SetProperty(TUid aCategory, TUint aKey, const TDesC16 &aValue) sl@0: { sl@0: TBuf<64> args; sl@0: args.AppendNum(aCategory.iUid); sl@0: args.Append(KSeparator); sl@0: args.AppendNum(aKey); sl@0: args.Append(KSeparator); sl@0: sl@0: //Need to check maximum size of this field.... sl@0: if((args.Size() + aValue.Size()) < args.MaxSize()) sl@0: { sl@0: User::Panic(KPropertyManagerPanic,0); sl@0: } sl@0: sl@0: args.Append(aValue); sl@0: sl@0: return LaunchHelperProcess(ESetPropertyDes16,args); sl@0: }