commands/setcritical/setcritical.cpp
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // setcritical.cpp
       
     2 // 
       
     3 // Copyright (c) 2008 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #include <fshell/memoryaccesscmd.h>
       
    14 
       
    15 using namespace IoUtils;
       
    16 
       
    17 class CCmdSetcritical : public CMemoryAccessCommandBase
       
    18 	{
       
    19 public:
       
    20 	static CCommandBase* NewLC();
       
    21 	~CCmdSetcritical();
       
    22 private:
       
    23 	CCmdSetcritical();
       
    24 private: // From CCommandBase.
       
    25 	virtual const TDesC& Name() const;
       
    26 	virtual void DoRunL();
       
    27 	virtual void ArgumentsL(RCommandArgumentList& aArguments);
       
    28 	virtual void OptionsL(RCommandOptionList& aOptions);
       
    29 private:
       
    30 	RArray<TUint> iTids;
       
    31 	TBool iSystem, iPermanent, iProcess, iCritical;
       
    32 	};
       
    33 
       
    34 
       
    35 CCommandBase* CCmdSetcritical::NewLC()
       
    36 	{
       
    37 	CCmdSetcritical* self = new(ELeave) CCmdSetcritical();
       
    38 	CleanupStack::PushL(self);
       
    39 	self->BaseConstructL();
       
    40 	return self;
       
    41 	}
       
    42 
       
    43 CCmdSetcritical::~CCmdSetcritical()
       
    44 	{
       
    45 	iTids.Close();
       
    46 	}
       
    47 
       
    48 CCmdSetcritical::CCmdSetcritical()
       
    49 	{
       
    50 	}
       
    51 
       
    52 const TDesC& CCmdSetcritical::Name() const
       
    53 	{
       
    54 	_LIT(KName, "setcritical");	
       
    55 	return KName;
       
    56 	}
       
    57 
       
    58 void CCmdSetcritical::ArgumentsL(RCommandArgumentList& aArguments)
       
    59 	{
       
    60 	aArguments.AppendUintL(iTids, _L("threadid"));
       
    61 	}
       
    62 
       
    63 void CCmdSetcritical::OptionsL(RCommandOptionList& aOptions)
       
    64 	{
       
    65 	aOptions.AppendBoolL(iSystem, _L("system"));
       
    66 	aOptions.AppendBoolL(iProcess, _L("process"));
       
    67 	aOptions.AppendBoolL(iCritical, _L("critical"));
       
    68 	aOptions.AppendBoolL(iPermanent, _L("permanent"));
       
    69 	}
       
    70 
       
    71 void CCmdSetcritical::DoRunL()
       
    72 	{
       
    73 	LoadMemoryAccessL();
       
    74 
       
    75 	TUint set = 0;
       
    76 	if (iSystem && iCritical)
       
    77 		set = KThreadFlagSystemCritical;
       
    78 	else if (iSystem && iPermanent)
       
    79 		set = KThreadFlagSystemPermanent;
       
    80 	else if (iProcess && iCritical)
       
    81 		set = KThreadFlagProcessCritical;
       
    82 	else if (iProcess && iPermanent)
       
    83 		set = KThreadFlagProcessPermanent;
       
    84 	else if (!iSystem && !iCritical && !iProcess && !iPermanent)
       
    85 		set = 0;
       
    86 	else
       
    87 		{
       
    88 		LeaveIfErr(KErrArgument, _L("Incompatible options specified. You must either give no options (to specify ENotCritical) or one of --system/--process and one of --critical/--permanent"));
       
    89 		}
       
    90 
       
    91 	for (TInt i = 0; i < iTids.Count(); i++)
       
    92 		{
       
    93 		TUint id = iTids[i];
       
    94 		RThread thread;
       
    95 		TInt err = iMemAccess.RThreadForceOpen(thread, id);
       
    96 		if (!err) err = iMemAccess.SetThreadCriticalFlags(thread, set);
       
    97 		if (err)
       
    98 			{
       
    99 			PrintError(err, _L("Couldn't set flags for thread %u."), id);
       
   100 			}
       
   101 		thread.Close();
       
   102 		}
       
   103 	}
       
   104 
       
   105 EXE_BOILER_PLATE(CCmdSetcritical)