applayerprotocols/httptransportfw/Test/T_HttpIntegration/CCmdMisc.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 // CCmdBase.cpp
       
    16 // This file contains the implementation for miscellaneous CCmd*
       
    17 // class' member functions. 
       
    18 // rev:	mjdavey, symbian@mjdss.com, July 2002
       
    19 // for:	Typhoon (7.0s) & JetStream (8.0)
       
    20 // Include Files  
       
    21 // 
       
    22 //
       
    23 
       
    24 #include "CCmdMisc.h"
       
    25 
       
    26 //-----------------------------------------------------------------------------
       
    27 
       
    28 CCmdCase* CCmdCase::NewL( TInt aCommandId, const TDesC& aKeyphrase )
       
    29 //	These functions allocate a CASE command object and construct it.
       
    30 {
       
    31 CCmdCase* self = NewLC( aCommandId, aKeyphrase );
       
    32 CleanupStack::Pop();
       
    33 return self; 
       
    34 }
       
    35 
       
    36 //-----------------------------------------------------------------------------
       
    37 
       
    38 CCmdCase* CCmdCase::NewLC( TInt aCommandId, const TDesC& aKeyphrase )
       
    39 {
       
    40 CCmdCase* self = new (ELeave) CCmdCase();
       
    41 CleanupStack::PushL( self );
       
    42 self->ConstructL( aCommandId, aKeyphrase );
       
    43 return self;
       
    44 }
       
    45 
       
    46 //-----------------------------------------------------------------------------
       
    47 
       
    48 CCmdCase::~CCmdCase ( )
       
    49 //	This function destructs the CASE command object.
       
    50 {
       
    51 }
       
    52 
       
    53 //-----------------------------------------------------------------------------
       
    54 
       
    55 void CCmdCase::ConstructL(TInt          aCommandId,   // in: command identifier
       
    56 													const TDesC&  aKeyphrase )  // in: beginning of the command name
       
    57 //	This function constructs the CASE command object.
       
    58 {
       
    59 CCmdBase::ConstructL(aCommandId, aKeyphrase);
       
    60 }
       
    61 
       
    62 //-----------------------------------------------------------------------------
       
    63 
       
    64 TBool CCmdCase::Recognize(const TDesC& aCommand)
       
    65 //	This function overrides the CCmdBase::Recognize. 
       
    66 {
       
    67 // Recognize the command and extract the parameter=description.
       
    68 TPtrC param;
       
    69 TRAPD(ret, param.Set(ParamsL(aCommand)));
       
    70 if (ret != KErrNone) 
       
    71 	return EFalse;
       
    72 
       
    73 // Check if this case was selected and set the CASE's StepOver
       
    74 // flag and the command family's StepOver accordingly.
       
    75 param.Set(TfrLex::Trim( param));
       
    76 CCmdSelect *select = (CCmdSelect*)Family()->Command(ECmdSelect);
       
    77 TBool selected = (select == NULL || select->Selected(param));
       
    78 SetStepOver(!selected);
       
    79 Family()->SetStepOver(!selected);
       
    80 return ETrue;
       
    81 }
       
    82 
       
    83 //-----------------------------------------------------------------------------
       
    84 
       
    85 TInt CCmdCase::ProcessL(const TDesC& aCommand)      // command line
       
    86 //	This function parses and processes a CASE command line. As a matter of
       
    87 //	fact, processing the CASE command does nothing (but see the Recognize).
       
    88 {
       
    89 // Complete the test machine - will then get the next cmd
       
    90 Machine()->CompleteRequest();
       
    91 
       
    92 TPtrC param;
       
    93 TRAPD( ret, param.Set(ParamsL(aCommand)));
       
    94 if (ret != KErrNone) 
       
    95 	return Error(ret, KFmtErrInvalidCmd, &Keyphrase());
       
    96 return KErrNone;
       
    97 }
       
    98 
       
    99 //-----------------------------------------------------------------------------
       
   100 //-----------------------------------------------------------------------------
       
   101 // CCmdEndCase
       
   102 //-----------------------------------------------------------------------------
       
   103 //-----------------------------------------------------------------------------
       
   104 
       
   105 CCmdEndCase* CCmdEndCase::NewL( TInt aCommandId, const TDesC& aKeyphrase )
       
   106 //	These functions allocate a END CASE command object and construct it.
       
   107 {
       
   108 CCmdEndCase* self = NewLC( aCommandId, aKeyphrase );
       
   109 CleanupStack::Pop();
       
   110 return self; 
       
   111 }
       
   112 
       
   113 //-----------------------------------------------------------------------------
       
   114 
       
   115 CCmdEndCase* CCmdEndCase::NewLC( TInt aCommandId, const TDesC& aKeyphrase )
       
   116 {
       
   117 CCmdEndCase* self = new (ELeave) CCmdEndCase();
       
   118 CleanupStack::PushL( self );
       
   119 self->ConstructL( aCommandId, aKeyphrase );
       
   120 return self;
       
   121 }
       
   122 
       
   123 //-----------------------------------------------------------------------------
       
   124 
       
   125 CCmdEndCase::~CCmdEndCase()
       
   126 {
       
   127 }
       
   128 
       
   129 //-----------------------------------------------------------------------------
       
   130 
       
   131 void CCmdEndCase::ConstructL(TInt aCommandId,   // in: command identifier
       
   132 														 const TDesC &aKeyphrase)  // in: beginning of the command name
       
   133 {
       
   134 CCmdBase::ConstructL(aCommandId, aKeyphrase);
       
   135 }
       
   136 
       
   137 //-----------------------------------------------------------------------------
       
   138 
       
   139 TBool CCmdEndCase::Recognize( const TDesC& aCommand  )
       
   140 //	This function overrides the CCmdBase::Recognize
       
   141 {
       
   142 // Recognize the command and extract the remainder (is ignored).
       
   143 TPtrC param;
       
   144 TRAPD( ret, param.Set( ParamsL( aCommand )) );
       
   145 if ( ret != KErrNone ) 
       
   146 	return EFalse;
       
   147 // Set this END CASE command's StepOver as in command family
       
   148 SetStepOver( Family()->StepOver() );
       
   149 // Reset the command family's StepOver flag back to false i.e.
       
   150 // commands will be processed starting from the next one.
       
   151 Family()->SetStepOver( EFalse );
       
   152 return ETrue;
       
   153 }
       
   154 
       
   155 //-----------------------------------------------------------------------------
       
   156 
       
   157 TInt CCmdEndCase::ProcessL ( const TDesC& aCommand)      // command line
       
   158 //	This function parses and processes a END CASE command line. As a matter
       
   159 //	of fact, processing the END CASE command in here does nothing (but see
       
   160 //	the Recognize).
       
   161 {
       
   162 // Complete the test machine - will then get the next cmd
       
   163 Machine()->CompleteRequest();
       
   164 
       
   165 TPtrC param;
       
   166 TRAPD( ret, param.Set( ParamsL( aCommand )) );
       
   167 if ( ret != KErrNone ) return Error(ret, KFmtErrInvalidCmd, &Keyphrase());
       
   168 return ret; // = KErrNone
       
   169 }
       
   170 
       
   171 //-----------------------------------------------------------------------------
       
   172 //-----------------------------------------------------------------------------
       
   173 // CCmdSelect
       
   174 //-----------------------------------------------------------------------------
       
   175 //-----------------------------------------------------------------------------
       
   176 
       
   177 CCmdSelect* CCmdSelect::NewL( TInt aCommandId, const TDesC& aKeyphrase )
       
   178 //	These functions allocate a CCmdSelect command object and construct it.
       
   179 {
       
   180 CCmdSelect* self = NewLC( aCommandId, aKeyphrase );
       
   181 CleanupStack::Pop();
       
   182 return self; 
       
   183 }
       
   184 
       
   185 //-----------------------------------------------------------------------------
       
   186 
       
   187 CCmdSelect* CCmdSelect::NewLC( TInt aCommandId, const TDesC& aKeyphrase )
       
   188 {
       
   189 CCmdSelect* self = new (ELeave) CCmdSelect();
       
   190 CleanupStack::PushL( self );
       
   191 self->ConstructL( aCommandId, aKeyphrase );
       
   192 return self;
       
   193 }
       
   194 
       
   195 //-----------------------------------------------------------------------------
       
   196 
       
   197 CCmdSelect::~CCmdSelect()
       
   198 {
       
   199 delete iSelector;
       
   200 iSelector = NULL;
       
   201 }
       
   202 
       
   203 //-----------------------------------------------------------------------------
       
   204 
       
   205 void CCmdSelect::ConstructL(TInt          aCommandId,   // in: command identifier
       
   206 														const TDesC&  aKeyphrase )  // in: beginning of the command name
       
   207 //	This function constructs the CCmdSelect command object.
       
   208 {
       
   209 CCmdBase::ConstructL(aCommandId, aKeyphrase);
       
   210 iSelector = NULL; // This means SELECT ALL!
       
   211 }
       
   212 
       
   213 //-----------------------------------------------------------------------------
       
   214 
       
   215 TInt CCmdSelect::ProcessL(const TDesC& aCommand)      // command line
       
   216 //	This function parses and processes a CCmdSelect command line
       
   217 {
       
   218 // Complete the test machine
       
   219 Machine()->CompleteRequest();
       
   220 
       
   221 TPtrC param;
       
   222 TRAPD(ret, param.Set(ParamsL(aCommand)));
       
   223 if (ret != KErrNone)
       
   224 	return Error(ret, TFR_KFmtErrBadCmd, &Keyphrase());
       
   225 
       
   226 if (Family()->Switch(CCmdFamily::EParseOnly))
       
   227 	return ret;
       
   228 
       
   229 // This is the selector string.
       
   230 param.Set(TfrLex::Trim(param));
       
   231 
       
   232 // Delete old selector if any and make a new one.
       
   233 if (iSelector != NULL)	
       
   234 	delete iSelector;
       
   235 
       
   236 iSelector = NULL; // This means ALL.
       
   237 if (param.Length() > 0)
       
   238 	{
       
   239 	iSelector = param.Alloc();
       
   240 	if (iSelector == NULL)
       
   241 		{
       
   242 		ret = KErrNoMemory;
       
   243 		Printf(TFR_KFmtErrFailed, &Keyphrase(), ret);
       
   244 		}
       
   245 	}
       
   246 
       
   247 return ret;
       
   248 }
       
   249 
       
   250 //-----------------------------------------------------------------------------
       
   251 
       
   252 TPtrC CCmdSelect::Selector() const
       
   253 //	This function gives the present selector
       
   254 {
       
   255 TPtrC selector = iSelector->Des();
       
   256 return selector;
       
   257 }
       
   258 
       
   259 //-----------------------------------------------------------------------------
       
   260 
       
   261 TBool CCmdSelect::Selected(const TDesC &aCandidate)
       
   262 //	This function checks if a candidate is selected.
       
   263 {
       
   264 // Having no selector means select ALL.
       
   265 if ( iSelector == NULL ) 
       
   266 	return ETrue;
       
   267 
       
   268 // Having empty selector means select NONE.
       
   269 if ( iSelector->Length() == 0 ) 
       
   270 	return EFalse;
       
   271 
       
   272 // Selectors ALL and NONE are accepted as well.
       
   273 if ( iSelector->Des().CompareF( _L("ALL"))  == 0 ) 
       
   274 	return ETrue;
       
   275 if ( iSelector->Des().CompareF( _L("NONE")) == 0 ) 
       
   276 	return EFalse;
       
   277 
       
   278 // Otherwise any match will do.
       
   279 return (aCandidate.MatchF( iSelector->Des() ) != KErrNotFound);
       
   280 }
       
   281 
       
   282 //-----------------------------------------------------------------------------
       
   283 //  End of File  
       
   284 //-----------------------------------------------------------------------------