applayerprotocols/httptransportfw/Test/T_HttpIntegration/CCmdFamily.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2002-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 // $Header$
       
    15 // GT0149 Applications Protocol Integration Test Harness
       
    16 // blank application
       
    17 // This module implements the CCmdFamily class: a generic collection of
       
    18 // registered CCmdBase class derived commands.
       
    19 // 
       
    20 //
       
    21 
       
    22 #include "CCmdBase.h"            //
       
    23 
       
    24 //	bizarre configuration means that this is the only way this will compile...
       
    25 //#include "CCmdFamily.h"            //
       
    26 
       
    27 //-----------------------------------------------------------------------------
       
    28 
       
    29 CCmdFamily* CCmdFamily::NewL ()
       
    30 {
       
    31 CCmdFamily* self = NewLC();
       
    32 CleanupStack::Pop();
       
    33 return self; 
       
    34 }
       
    35 
       
    36 //-----------------------------------------------------------------------------
       
    37 
       
    38 CCmdFamily* CCmdFamily::NewLC()
       
    39 {
       
    40 CCmdFamily* self = new (ELeave) CCmdFamily();
       
    41 CleanupStack::PushL(self);
       
    42 self->ConstructL();
       
    43 return self;
       
    44 }
       
    45 
       
    46 //-----------------------------------------------------------------------------
       
    47 
       
    48 void CCmdFamily::ConstructL()
       
    49 {
       
    50 
       
    51 iMachine  = NULL;
       
    52 iStepOver = EFalse;
       
    53 
       
    54 // Perhaps the granularity should be approximated in advance?
       
    55 TInt granularity = 32; // this one here is just a wild guess
       
    56 iCommands = new (ELeave) CArrayPtrSeg<CCmdBase>(granularity);
       
    57 
       
    58 //
       
    59 // Assuming a TBool array to be initially full of EFalse's?
       
    60 //
       
    61 
       
    62 }
       
    63 
       
    64 //-----------------------------------------------------------------------------
       
    65 
       
    66 CCmdFamily::~CCmdFamily()
       
    67 {
       
    68 iCommands->ResetAndDestroy();
       
    69 delete iCommands;
       
    70 }
       
    71 
       
    72 //-----------------------------------------------------------------------------
       
    73 
       
    74 void CCmdFamily::SetMachine(CTEngine *aTestMachine)
       
    75 {
       
    76 iMachine = aTestMachine;
       
    77 }
       
    78 
       
    79 //-----------------------------------------------------------------------------
       
    80 
       
    81 CTEngine* CCmdFamily::Machine()
       
    82 {
       
    83 return iMachine;
       
    84 }
       
    85 
       
    86 //-----------------------------------------------------------------------------
       
    87 //	use this to append a new command to the list
       
    88 
       
    89 void CCmdFamily::RegisterL(CCmdBase* aCommand) 
       
    90 {
       
    91 if (aCommand != 0)
       
    92 	{
       
    93 	iCommands->AppendL(aCommand);
       
    94 	aCommand->SetFamily(this);
       
    95 	}
       
    96 }
       
    97 
       
    98 //-----------------------------------------------------------------------------
       
    99 //	returns how many commands currently available
       
   100 
       
   101 TInt CCmdFamily::Count() const
       
   102 {
       
   103 return iCommands->Count();
       
   104 }
       
   105 
       
   106 //-----------------------------------------------------------------------------
       
   107 //	returns a pointer to aIndex'th command
       
   108 
       
   109 CCmdBase* CCmdFamily::At(TInt aIndex) const
       
   110 {
       
   111 return iCommands->At(aIndex);
       
   112 }
       
   113 
       
   114 //-----------------------------------------------------------------------------
       
   115 //	operator to get at particular command
       
   116 
       
   117 CCmdBase* CCmdFamily::operator[](TInt aIndex) const
       
   118 {
       
   119 return iCommands->At(aIndex);
       
   120 }
       
   121 
       
   122 //-----------------------------------------------------------------------------
       
   123 //	get command with this ID
       
   124 
       
   125 CCmdBase* CCmdFamily::Command(TInt aCommandId)
       
   126 {
       
   127 for (TInt i = 0; i < Count(); ++i)
       
   128 	{
       
   129 	CCmdBase* command = At(i);
       
   130 	if (command->CommandId() == aCommandId) 
       
   131 		return command;
       
   132 	}
       
   133 
       
   134 // Not found
       
   135 return NULL;
       
   136 }
       
   137 
       
   138 //-----------------------------------------------------------------------------
       
   139 //	Get Command by command string i.e. recognize the command.
       
   140 
       
   141 CCmdBase *CCmdFamily::Recognize(const TDesC& aCommand)
       
   142 {
       
   143 for (TInt i = 0; i < Count(); ++i)
       
   144 	{
       
   145 	CCmdBase *command = At(i);
       
   146 	if (command->Recognize(aCommand)) 
       
   147 		return command;
       
   148 	}
       
   149 
       
   150 // Not found
       
   151 return NULL;
       
   152 }
       
   153 
       
   154 //-----------------------------------------------------------------------------
       
   155 //-----------------------------------------------------------------------------
       
   156 //
       
   157 //	Command Family Methods
       
   158 //
       
   159 //-----------------------------------------------------------------------------
       
   160 //-----------------------------------------------------------------------------
       
   161 
       
   162 //-----------------------------------------------------------------------------
       
   163 //	List all the commands out one by one!
       
   164 //	added mjd, Aug.2002
       
   165 
       
   166 void CCmdFamily::ListAll(CConsoleBase *aConsole)
       
   167 {
       
   168 _LIT(KHdr, "\r\n    Command            Help Information");
       
   169 _LIT(KMsg, "\r\n%3d %-16S - %-52S");
       
   170 
       
   171 if (aConsole != 0)
       
   172 	aConsole->Printf(KHdr);
       
   173 
       
   174 TInt i = 0;
       
   175 TInt j = 0;
       
   176 while (j < Count())
       
   177 	{
       
   178 	if (aConsole)
       
   179 		{
       
   180 		CCmdBase* iCmd = At(j);
       
   181 		aConsole->Printf(KMsg, j, &iCmd->Keyphrase(), &iCmd->HelpText());
       
   182 		if (i > 12)
       
   183 			{
       
   184 			aConsole->Printf(_L("\r\n[Press any key]"));
       
   185 			aConsole->Getch();
       
   186 			aConsole->Printf(KHdr);
       
   187 			i = 0;
       
   188 			}
       
   189 		}
       
   190 	++i;
       
   191 	++j;
       
   192 	}
       
   193 
       
   194 //	one final CRLF to ensure we display the prompt on a new line...
       
   195 aConsole->Printf(_L("\n"));
       
   196 }
       
   197 
       
   198 //-----------------------------------------------------------------------------
       
   199 //	Set the switch (default aBoolean to TRUE)
       
   200 
       
   201 void CCmdFamily::SetSwitch(const TSwitch &aSwitch, TBool aBoolean)
       
   202 {
       
   203 iSwitch[aSwitch] = aBoolean;
       
   204 }
       
   205 
       
   206 //-----------------------------------------------------------------------------
       
   207 //	Get the switch
       
   208 
       
   209 TBool CCmdFamily::Switch(const TSwitch &aSwitch)
       
   210 {
       
   211 return iSwitch[aSwitch];
       
   212 }
       
   213 
       
   214 //-----------------------------------------------------------------------------
       
   215 //	Set the StepOver flag.
       
   216 
       
   217 void CCmdFamily::SetStepOver(const TBool &aBoolean)
       
   218 {
       
   219 iStepOver = aBoolean;
       
   220 }
       
   221 
       
   222 //-----------------------------------------------------------------------------
       
   223 //	Get the StepOver flag.
       
   224 
       
   225 TBool CCmdFamily::StepOver()
       
   226 {
       
   227 return iStepOver;
       
   228 }
       
   229 
       
   230 //-----------------------------------------------------------------------------
       
   231 //  End of File  
       
   232 //-----------------------------------------------------------------------------