stif/TestInterface/src/StifTFwIfProt.cpp
branchRCL_3
changeset 59 8ad140f3dd41
parent 0 a03f92240627
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "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 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description: This file conatins StifTfIfProt implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32base.h>
       
    20 #include <e32svr.h>
       
    21 #include "StifTFwIfProt.h"
       
    22 
       
    23 #include <StifLogger.h>
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 //extern  ?external_data;
       
    27 
       
    28 // EXTERNAL FUNCTION PROTOTYPES  
       
    29 //extern ?external_function( ?arg_type,?arg_type );
       
    30 
       
    31 // CONSTANTS
       
    32 //const ?type ?constant_var = ?constant;
       
    33 
       
    34 // MACROS
       
    35 //#define DEBUG(a) RDebug::Print(a)
       
    36 //#define DEBUG2(a,b) RDebug::Print(a,b)
       
    37 //#define DEBUG3(a,b,c) RDebug::Print(a,b,c)
       
    38 #define DEBUG(a)
       
    39 #define DEBUG2(a,b)
       
    40 #define DEBUG3(a,b,c)
       
    41 #define ERROR RDebug::Print
       
    42 
       
    43 // LOCAL CONSTANTS AND MACROS
       
    44 //const ?type ?constant_var = ?constant;
       
    45 //#define ?macro_name ?macro_def
       
    46 
       
    47 // MODULE DATA STRUCTURES
       
    48 //enum ?declaration
       
    49 //typedef ?declaration
       
    50 
       
    51 // LOCAL FUNCTION PROTOTYPES
       
    52 //?type ?function_name( ?arg_type, ?arg_type );
       
    53 
       
    54 // FORWARD DECLARATIONS
       
    55 //class ?FORWARD_CLASSNAME;
       
    56 
       
    57 // ==================== LOCAL FUNCTIONS =======================================
       
    58 
       
    59 /*
       
    60 -------------------------------------------------------------------------------
       
    61 
       
    62     Function: <function name>
       
    63 
       
    64     Description: <one line description>
       
    65 
       
    66     <Description of the functionality 
       
    67     description continues and...
       
    68     continues>
       
    69 
       
    70     Parameters:	<arg1>: <in/out/inout>: <accepted values>: <Description>
       
    71     
       
    72     Return Values: <value_1: Description
       
    73 		            value_n: Description line 1
       
    74 			                 description line 2>
       
    75 
       
    76     Errors/Exceptions: <description how errors and exceptions are handled>
       
    77 
       
    78     Status: Draft
       
    79 
       
    80 -------------------------------------------------------------------------------
       
    81 */
       
    82 /*
       
    83 <type function_name(
       
    84     <arg_type arg,>  
       
    85     <arg_type arg >)  	
       
    86     {
       
    87     // <comment>
       
    88     <code> 
       
    89     
       
    90     // <comment>
       
    91     <code>
       
    92     }
       
    93 */
       
    94 
       
    95 
       
    96 /*
       
    97 -------------------------------------------------------------------------------
       
    98 
       
    99     DESCRIPTION
       
   100 
       
   101     This module contains the implementation of CStifTFwIfProt class 
       
   102 	member functions.
       
   103 
       
   104 -------------------------------------------------------------------------------
       
   105 */
       
   106 
       
   107 // ================= MEMBER FUNCTIONS =========================================
       
   108 
       
   109 /*
       
   110 -------------------------------------------------------------------------------
       
   111 
       
   112     Class: CStifTFwIfProt
       
   113 
       
   114     Method: CStifTFwIfProt
       
   115 
       
   116     Description: Default constructor
       
   117 
       
   118     C++ default constructor can NOT contain any code, that
       
   119     might leave.
       
   120     
       
   121     Parameters:	none
       
   122     
       
   123     Return Values: None
       
   124     
       
   125     Errors/Exceptions: None
       
   126     
       
   127     Status: Draft
       
   128 	
       
   129 -------------------------------------------------------------------------------
       
   130 */
       
   131 CStifTFwIfProt::CStifTFwIfProt(): iMessage(0,0)
       
   132     { 
       
   133     };
       
   134     
       
   135 /*
       
   136 -------------------------------------------------------------------------------
       
   137 
       
   138      Class: CStifTFwIfProt
       
   139 
       
   140      Method: ConstructL
       
   141 
       
   142      Description: Symbian OS second phase constructor
       
   143 
       
   144      Symbian OS default constructor can leave.
       
   145 
       
   146      Parameters:    None
       
   147 
       
   148      Return Values: None
       
   149 
       
   150      Errors/Exceptions: None.
       
   151 
       
   152      Status: Proposal
       
   153     
       
   154 -------------------------------------------------------------------------------
       
   155 */
       
   156 void CStifTFwIfProt::ConstructL()
       
   157     {        
       
   158 
       
   159     }
       
   160 
       
   161 /*
       
   162 -------------------------------------------------------------------------------
       
   163 
       
   164      Class: CStifTFwIfProt
       
   165 
       
   166      Method: NewL
       
   167 
       
   168      Description: Two-phased constructor.
       
   169           
       
   170      Parameters:    None
       
   171 
       
   172      Return Values: CStifTFwIfProt*: new object
       
   173 
       
   174      Errors/Exceptions: Leaves if new or ConstructL leaves and in oom.
       
   175 
       
   176      Status: Proposal
       
   177     
       
   178 -------------------------------------------------------------------------------
       
   179 */
       
   180 EXPORT_C CStifTFwIfProt* CStifTFwIfProt::NewL()
       
   181     {
       
   182      
       
   183     CStifTFwIfProt* self = new (ELeave) CStifTFwIfProt();
       
   184     
       
   185     CleanupStack::PushL( self );
       
   186     self->ConstructL();
       
   187     CleanupStack::Pop();
       
   188 
       
   189     return self;
       
   190      
       
   191     }
       
   192 
       
   193 /*
       
   194 -------------------------------------------------------------------------------
       
   195 
       
   196     Class: CStifTFwIfProt
       
   197 
       
   198     Method: ~CStifTFwIfProt
       
   199 
       
   200     Description: Destructor
       
   201 
       
   202     Parameters:	None
       
   203     
       
   204     Return Values: None
       
   205     
       
   206     Errors/Exceptions: None
       
   207     
       
   208     Status: Draft
       
   209 	
       
   210 -------------------------------------------------------------------------------
       
   211 */    
       
   212 
       
   213 EXPORT_C CStifTFwIfProt::~CStifTFwIfProt()
       
   214     {
       
   215     
       
   216     delete iItem;
       
   217     delete iMessageBuf;
       
   218     iMessageBuf = NULL;
       
   219     
       
   220     }
       
   221 
       
   222 /*
       
   223 -------------------------------------------------------------------------------
       
   224 
       
   225     Class: CStifTFwIfProt
       
   226 
       
   227     Method: CreateL
       
   228 
       
   229     Description: Create new empty protocol message.
       
   230 
       
   231     Parameters:	TInt aLength: in: protocol message length
       
   232     
       
   233     Return Values: None
       
   234     
       
   235     Errors/Exceptions: Leave if oom.
       
   236     
       
   237     Status: Draft
       
   238 	
       
   239 -------------------------------------------------------------------------------
       
   240 */
       
   241 EXPORT_C void CStifTFwIfProt::CreateL( TInt aLength )
       
   242     {
       
   243     
       
   244     // Delete previous if exists
       
   245     delete iMessageBuf;
       
   246     iMessageBuf = NULL;
       
   247     iMessage.Set( 0, 0, 0 );
       
   248     
       
   249     iMessageBuf = HBufC::NewL( aLength );
       
   250     iMessage.Set( iMessageBuf->Des() );
       
   251             
       
   252     }
       
   253 
       
   254 /*
       
   255 -------------------------------------------------------------------------------
       
   256 
       
   257     Class: CStifTFwIfProt
       
   258 
       
   259     Method: Append
       
   260 
       
   261     Description: Append string to protocol message.
       
   262 
       
   263     Parameters:	TInt aLength: in: protocol message length
       
   264     
       
   265     Return Values: None
       
   266     
       
   267     Errors/Exceptions: Leave if oom.
       
   268     
       
   269     Status: Draft
       
   270 	
       
   271 -------------------------------------------------------------------------------
       
   272 */   
       
   273 EXPORT_C TInt CStifTFwIfProt::Append( const TDesC& aStr )
       
   274     {
       
   275     
       
   276     if( ( aStr.Length() + 1 ) >
       
   277         ( iMessage.MaxLength() - iMessage.Length() ) )
       
   278         {
       
   279         ERROR( _L("No space left for string") );
       
   280         return KErrOverflow;   
       
   281         }
       
   282     iMessage.Append( aStr );
       
   283     iMessage.Append( _L(" ") );
       
   284     
       
   285     return KErrNone;
       
   286 
       
   287     }    
       
   288 
       
   289 /*
       
   290 -------------------------------------------------------------------------------
       
   291 
       
   292     Class: CStifTFwIfProt
       
   293 
       
   294     Method: Append
       
   295 
       
   296     Description: Append hexadecimal value to protocol message.
       
   297 
       
   298     Parameters:	TInt aLength: in: protocol message length
       
   299     
       
   300     Return Values: None
       
   301     
       
   302     Errors/Exceptions: Leave if oom.
       
   303     
       
   304     Status: Draft
       
   305 	
       
   306 -------------------------------------------------------------------------------
       
   307 */   
       
   308 EXPORT_C TInt CStifTFwIfProt::AppendId( TUint32 aId )
       
   309     {
       
   310     
       
   311      if( ( KMaxValueLength + 1 ) >
       
   312         ( iMessage.MaxLength() - iMessage.Length() ) )
       
   313         {
       
   314         ERROR( _L("No space left for string") );
       
   315         return KErrOverflow;   
       
   316         }
       
   317         
       
   318     iMessage.AppendNumFixedWidth( aId, EHex, KProtocolIdLength );
       
   319     iMessage.Append( _L(" ") );
       
   320     
       
   321     return KErrNone;
       
   322 
       
   323     }
       
   324         
       
   325 /*
       
   326 -------------------------------------------------------------------------------
       
   327 
       
   328     Class: CStifTFwIfProt
       
   329 
       
   330     Method: Append
       
   331 
       
   332     Description: Append string to protocol message.
       
   333 
       
   334     Parameters:	TInt aLength: in: protocol message length
       
   335     
       
   336     Return Values: None
       
   337     
       
   338     Errors/Exceptions: Leave if oom.
       
   339 
       
   340     Status: Draft
       
   341 	
       
   342 -------------------------------------------------------------------------------
       
   343 */   
       
   344 EXPORT_C TInt CStifTFwIfProt::Append( KeywordFunc aFunc, TInt aKeyword )
       
   345     {
       
   346     
       
   347     if( ( aFunc( aKeyword ).Length() + 1 ) >
       
   348         ( iMessage.MaxLength() - iMessage.Length() ) )
       
   349         {
       
   350         ERROR( _L("No space left for string") );
       
   351         return KErrOverflow;   
       
   352         }
       
   353     iMessage.Append( aFunc( aKeyword ) );
       
   354     iMessage.Append( _L(" ") );
       
   355     
       
   356     return KErrNone;
       
   357 
       
   358     }
       
   359     
       
   360 /*
       
   361 -------------------------------------------------------------------------------
       
   362 
       
   363     Class: CStifTFwIfProt
       
   364 
       
   365     Method: Append
       
   366 
       
   367     Description: Append type-value string to protocol message.
       
   368 
       
   369     Parameters:	TInt aLength: in: protocol message length
       
   370     
       
   371     Return Values: None
       
   372     
       
   373     Errors/Exceptions: Leave if oom.
       
   374     
       
   375     Status: Draft
       
   376 	
       
   377 -------------------------------------------------------------------------------
       
   378 */   
       
   379 EXPORT_C TInt CStifTFwIfProt::Append( KeywordFunc aFunc, 
       
   380                                       TInt aKeyword, 
       
   381                                       const TDesC& aStr )
       
   382     {
       
   383     
       
   384      if( ( aFunc( aKeyword ).Length() + 2 +  aStr.Length() ) >
       
   385         ( iMessage.MaxLength() - iMessage.Length() ) )
       
   386         {
       
   387         ERROR( _L("No space left for string") );
       
   388         return KErrOverflow;
       
   389         }
       
   390         
       
   391     iMessage.Append( aFunc( aKeyword ) );
       
   392     iMessage.Append( _L("=") );
       
   393     iMessage.Append( aStr );
       
   394     iMessage.Append( _L(" ") );
       
   395     
       
   396     return KErrNone;
       
   397 
       
   398     }
       
   399     
       
   400 /*
       
   401 -------------------------------------------------------------------------------
       
   402 
       
   403     Class: CStifTFwIfProt
       
   404 
       
   405     Method: Append
       
   406 
       
   407     Description: Append type-value string to protocol message.
       
   408 
       
   409     Parameters:	TInt aLength: in: protocol message length
       
   410     
       
   411     Return Values: None
       
   412     
       
   413     Errors/Exceptions: Leave if oom.
       
   414     
       
   415     Status: Draft
       
   416 	
       
   417 -------------------------------------------------------------------------------
       
   418 */   
       
   419 EXPORT_C TInt CStifTFwIfProt::Append( KeywordFunc aFunc, 
       
   420                                       TInt aKeyword, 
       
   421                                       KeywordFunc aValueFunc, 
       
   422                                       TInt aValue )
       
   423     {
       
   424     
       
   425      if( ( aFunc( aKeyword ).Length() + 2 +  aValueFunc( aValue ).Length() ) >
       
   426         ( iMessage.MaxLength() - iMessage.Length() ) )
       
   427         {
       
   428         ERROR( _L("No space left for string") );
       
   429         return KErrOverflow;   
       
   430         }
       
   431         
       
   432     iMessage.Append( aFunc( aKeyword ) );
       
   433     iMessage.Append( _L("=") );
       
   434     iMessage.Append( aValueFunc( aValue ) );
       
   435     iMessage.Append( _L(" ") );
       
   436     
       
   437     return KErrNone;
       
   438 
       
   439     }
       
   440 
       
   441 /*
       
   442 -------------------------------------------------------------------------------
       
   443 
       
   444     Class: CStifTFwIfProt
       
   445 
       
   446     Method: Append
       
   447 
       
   448     Description: Append type-value string to protocol message.
       
   449 
       
   450     Parameters:	TInt aLength: in: protocol message length
       
   451     
       
   452     Return Values: None
       
   453     
       
   454     Errors/Exceptions: Leave if oom.
       
   455     
       
   456     Status: Draft
       
   457 	
       
   458 -------------------------------------------------------------------------------
       
   459 */   
       
   460 EXPORT_C TInt CStifTFwIfProt::Append( KeywordFunc aFunc, 
       
   461                                        TInt aKeyword, 
       
   462                                        TInt aValue )
       
   463     {
       
   464     
       
   465      if( ( aFunc( aKeyword ).Length() + 2 + KMaxValueLength ) >
       
   466         ( iMessage.MaxLength() - iMessage.Length() ) )
       
   467         {
       
   468         ERROR( _L("No space left for string") );
       
   469         return KErrOverflow;   
       
   470         }
       
   471         
       
   472     iMessage.Append( aFunc( aKeyword ) );
       
   473     iMessage.Append( _L("=") );
       
   474     iMessage.AppendNum( aValue );
       
   475     iMessage.Append( _L(" ") );
       
   476     
       
   477     return KErrNone;
       
   478 
       
   479     }
       
   480         
       
   481 /*
       
   482 -------------------------------------------------------------------------------
       
   483 
       
   484     Class: CStifTFwIfProt
       
   485 
       
   486     Method: SetL
       
   487 
       
   488     Description: Set and parse protocol message.
       
   489 
       
   490     Parameters:	TDesC& aMessage: in: protocol message
       
   491     
       
   492     Return Values: Symbian OS error code: If protocol message parsing fails, 
       
   493         i.e. message prsing after header <msg type> <sdcid> <dstid>
       
   494     
       
   495     Errors/Exceptions: Leaves if protocol header parsing fails and oom.
       
   496     
       
   497     Status: Draft
       
   498 	
       
   499 -------------------------------------------------------------------------------
       
   500 */
       
   501 EXPORT_C TInt CStifTFwIfProt::SetL( const TDesC& aMessage )
       
   502     {
       
   503     
       
   504     // Delete previous if exists
       
   505     delete iMessageBuf;
       
   506     iMessageBuf = NULL;
       
   507     iMessage.Set( 0,0,0 );
       
   508     
       
   509     iMessageBuf = aMessage.AllocL();
       
   510     iMessage.Set( iMessageBuf->Des() );
       
   511     
       
   512     return ParseMessageL();
       
   513         
       
   514     }
       
   515             
       
   516 /*
       
   517 -------------------------------------------------------------------------------
       
   518 
       
   519     Class: CStifTFwIfProt
       
   520 
       
   521     Method: SetL
       
   522 
       
   523     Description: Get protocol source identifier.
       
   524 
       
   525     Parameters:	None
       
   526     
       
   527     Return Values: Source identifier.
       
   528     
       
   529     Errors/Exceptions: None.
       
   530 
       
   531     Status: Draft
       
   532 	
       
   533 -------------------------------------------------------------------------------
       
   534 */
       
   535 EXPORT_C TUint32 CStifTFwIfProt::SrcId()
       
   536     {
       
   537     
       
   538     return iSrcId;    
       
   539     
       
   540     }
       
   541 
       
   542 /*
       
   543 -------------------------------------------------------------------------------
       
   544 
       
   545     Class: CStifTFwIfProt
       
   546 
       
   547     Method: SetL
       
   548 
       
   549     Description: Get protocol source device identifier.
       
   550 
       
   551     Parameters:	None
       
   552     
       
   553     Return Values: Source device identifier.
       
   554     
       
   555     Errors/Exceptions: None.
       
   556     
       
   557     Status: Draft
       
   558 	
       
   559 -------------------------------------------------------------------------------
       
   560 */
       
   561 EXPORT_C TUint16 CStifTFwIfProt::SrcDevId()
       
   562     {
       
   563     
       
   564     return DEVID( iSrcId );  
       
   565         
       
   566     }
       
   567 
       
   568 /*
       
   569 -------------------------------------------------------------------------------
       
   570 
       
   571     Class: CStifTFwIfProt
       
   572 
       
   573     Method: SetL
       
   574 
       
   575     Description: Get protocol source test identifier.
       
   576 
       
   577     Parameters:	None
       
   578     
       
   579     Return Values: Source test identifier.
       
   580     
       
   581     Errors/Exceptions: None.
       
   582 
       
   583     Status: Draft
       
   584 
       
   585 -------------------------------------------------------------------------------
       
   586 */
       
   587 EXPORT_C TUint16 CStifTFwIfProt::SrcTestId()
       
   588     {
       
   589 
       
   590     return TESTID( iSrcId );  
       
   591     
       
   592     }
       
   593 
       
   594 /*
       
   595 -------------------------------------------------------------------------------
       
   596 
       
   597     Class: CStifTFwIfProt
       
   598 
       
   599     Method: SetL
       
   600 
       
   601     Description: Get protocol destination identifier.
       
   602 
       
   603     Parameters:	None
       
   604     
       
   605     Return Values: Destination identifier.
       
   606     
       
   607     Errors/Exceptions: None.
       
   608 
       
   609     Status: Draft
       
   610 	
       
   611 -------------------------------------------------------------------------------
       
   612 */
       
   613 EXPORT_C TUint32 CStifTFwIfProt::DstId()
       
   614     {
       
   615     
       
   616     return iDstId;  
       
   617 
       
   618     }
       
   619 
       
   620 /*
       
   621 -------------------------------------------------------------------------------
       
   622 
       
   623     Class: CStifTFwIfProt
       
   624 
       
   625     Method: SetL
       
   626 
       
   627     Description: Get protocol destination device identifier.
       
   628 
       
   629     Parameters:	None
       
   630     
       
   631     Return Values: Destination device identifier.
       
   632     
       
   633     Errors/Exceptions: None.
       
   634 
       
   635     Status: Draft
       
   636 	
       
   637 -------------------------------------------------------------------------------
       
   638 */
       
   639 EXPORT_C TUint16 CStifTFwIfProt::DstDevId()
       
   640     {
       
   641 
       
   642     return DEVID( iDstId );  
       
   643 
       
   644     }
       
   645 
       
   646 /*
       
   647 -------------------------------------------------------------------------------
       
   648 
       
   649     Class: CStifTFwIfProt
       
   650 
       
   651     Method: SetL
       
   652 
       
   653     Description: Get protocol destination test identifier.
       
   654 
       
   655     Parameters:	None
       
   656     
       
   657     Return Values: Destination test identifier.
       
   658     
       
   659     Errors/Exceptions: None.
       
   660 
       
   661     Status: Draft
       
   662 	
       
   663 -------------------------------------------------------------------------------
       
   664 */
       
   665 EXPORT_C TUint16 CStifTFwIfProt::DstTestId()
       
   666     {
       
   667 
       
   668     return TESTID( iDstId );  
       
   669     
       
   670     }
       
   671 
       
   672 
       
   673 /*
       
   674 -------------------------------------------------------------------------------
       
   675 
       
   676     Class: CStifTFwIfProt
       
   677 
       
   678     Method: ParseMessageL
       
   679 
       
   680     Description: Parse protocol message.
       
   681 
       
   682     Parameters:	None
       
   683 
       
   684     Return Values: None.
       
   685 
       
   686     Errors/Exceptions: None.
       
   687 
       
   688     Status: Draft
       
   689 
       
   690 -------------------------------------------------------------------------------
       
   691 */
       
   692 TInt CStifTFwIfProt::ParseMessageL()
       
   693     {
       
   694     RDebug::Print(_L("CStifTFwIfProt::ParseMessageL start"));
       
   695 
       
   696     RDebug::Print(_L("CStifTFwIfProt::ParseMessageL message content: (next line)"));
       
   697     RDebug::Print(iMessage);
       
   698 
       
   699     iItem = CStifItemParser::NewL( iMessage, 0, iMessage.Length() );
       
   700 
       
   701     ParseHeaderL();
       
   702 
       
   703     TRAPD( err,
       
   704     switch( iMsgType )
       
   705         {
       
   706         case EMsgReserve:
       
   707             RDebug::Print(_L("CStifTFwIfProt::ParseMessageL EMsgReserve"));
       
   708             ParseReserveL();
       
   709             break;
       
   710         case EMsgRelease:
       
   711             RDebug::Print(_L("CStifTFwIfProt::ParseMessageL EMsgRelease"));
       
   712             break;
       
   713         case EMsgRemote:
       
   714             RDebug::Print(_L("CStifTFwIfProt::ParseMessageL EMsgRemote"));
       
   715             ParseRemoteL();
       
   716             break;
       
   717         case EMsgResponse:
       
   718             RDebug::Print(_L("CStifTFwIfProt::ParseMessageL EMsgResponse"));
       
   719             ParseResponseL();
       
   720             break;
       
   721         default:
       
   722             RDebug::Print(_L("CStifTFwIfProt::ParseMessageL ERROR invalid message type. Leaving!!!"));
       
   723             ERROR( _L("Invalid message type") );        
       
   724             User::Leave( KErrArgument );
       
   725         }
       
   726     );
       
   727     
       
   728     delete iItem;
       
   729     iItem = 0;
       
   730     
       
   731     return err;
       
   732            
       
   733     }
       
   734     
       
   735 /*
       
   736 -------------------------------------------------------------------------------
       
   737 
       
   738     Class: CStifTFwIfProt
       
   739 
       
   740     Method: ParseHeaderL
       
   741 
       
   742     Description: Parse protocol header.
       
   743 
       
   744     Parameters:	None
       
   745     
       
   746     Return Values: None.
       
   747     
       
   748     Errors/Exceptions: None.
       
   749     
       
   750     Status: Draft
       
   751 	
       
   752 -------------------------------------------------------------------------------
       
   753 */
       
   754 void CStifTFwIfProt::ParseHeaderL()
       
   755     {
       
   756     
       
   757     TPtrC tmp;
       
   758     TInt ret;
       
   759     TInt tmpMsgType;
       
   760     
       
   761     // Get and parse message type    
       
   762     ret = iItem->GetString( _L(""), tmp );
       
   763     if( ret != KErrNone )
       
   764         {
       
   765         ERROR( _L("No message type given") );        
       
   766         User::Leave( KErrNotFound );
       
   767         }
       
   768         
       
   769     tmpMsgType = Parse( tmp, MsgType );
       
   770     if( tmpMsgType < 0 )
       
   771         {
       
   772         ERROR( _L("Invalid message type given") );        
       
   773         User::Leave( KErrArgument );
       
   774         }
       
   775 	iMsgType = ( TMsgType )tmpMsgType;
       
   776 
       
   777     // Get and parse srcid    
       
   778     ret = iItem->GetNextString( tmp );
       
   779     if( ret != KErrNone )
       
   780         {
       
   781         ERROR( _L("No srcid given") );        
       
   782         User::Leave( KErrNotFound );
       
   783         }
       
   784     // Check id length
       
   785     if( tmp.Length() != KProtocolIdLength )
       
   786         {
       
   787         ERROR( _L("Invalid srcid length [%d]"), tmp.Length() );        
       
   788         User::Leave( KErrArgument );
       
   789         }    
       
   790     TUint32 id;
       
   791     TLex lex( tmp );
       
   792     if( lex.Val( id, EHex ) != KErrNone )
       
   793         {
       
   794         ERROR( _L("Invalid srcid given") );        
       
   795         User::Leave( KErrArgument );
       
   796         }        
       
   797     iSrcId = id;
       
   798 
       
   799 
       
   800     // Get and parse dstid    
       
   801     ret = iItem->GetNextString( tmp );
       
   802     if( ret != KErrNone )
       
   803         {
       
   804         ERROR( _L("No dstid given") );        
       
   805         User::Leave( KErrNotFound );
       
   806         }
       
   807     // Check id length
       
   808     if( tmp.Length() != KProtocolIdLength )
       
   809         {
       
   810         ERROR( _L("Invalid srcid length [%d]"), tmp.Length() );        
       
   811         User::Leave( KErrArgument );
       
   812         }                    
       
   813     lex.Assign( tmp );
       
   814     if( lex.Val( id, EHex ) != KErrNone )
       
   815         {
       
   816         ERROR( _L("Invalid dstid given") );        
       
   817         User::Leave( KErrArgument );
       
   818         }        
       
   819     iDstId = id;
       
   820     
       
   821     }
       
   822     
       
   823     
       
   824 /*
       
   825 -------------------------------------------------------------------------------
       
   826 
       
   827     Class: CStifTFwIfProt
       
   828 
       
   829     Method: ParseReserveL
       
   830 
       
   831     Description: Parse protocol reserve message.
       
   832 
       
   833     Parameters:	None
       
   834     
       
   835     Return Values: None.
       
   836     
       
   837     Errors/Exceptions: None.
       
   838     
       
   839     Status: Draft
       
   840 	
       
   841 -------------------------------------------------------------------------------
       
   842 */
       
   843 void CStifTFwIfProt::ParseReserveL()
       
   844     {
       
   845     
       
   846     TPtrC tmp;
       
   847     TInt ret;
       
   848 	TInt tmpRemoteType;
       
   849     
       
   850     // Get and parse remote type    
       
   851     ret = iItem->GetNextString( tmp );
       
   852     if( ret != KErrNone )
       
   853         {
       
   854         ERROR( _L("No remote type given") );        
       
   855         User::Leave( KErrNotFound );
       
   856         }
       
   857             
       
   858     tmpRemoteType = Parse( tmp, RemoteType );
       
   859     if( tmpRemoteType < 0 )
       
   860         {
       
   861         iRemoteType = ERemoteUnknown;
       
   862         }
       
   863     else 
       
   864     	{
       
   865     	iRemoteType = ( TRemoteType ) tmpRemoteType;
       
   866     	}
       
   867         
       
   868     }
       
   869     
       
   870 /*
       
   871 -------------------------------------------------------------------------------
       
   872 
       
   873     Class: CStifTFwIfProt
       
   874 
       
   875     Method: ParseRemoteL
       
   876 
       
   877     Description: Parse protocol remote message.
       
   878 
       
   879     Parameters:	None
       
   880     
       
   881     Return Values: None.
       
   882     
       
   883     Errors/Exceptions: None.
       
   884     
       
   885     Status: Draft
       
   886 	
       
   887 -------------------------------------------------------------------------------
       
   888 */
       
   889 void CStifTFwIfProt::ParseRemoteL()
       
   890     {
       
   891     RDebug::Print(_L("CStifTFwIfProt::ParseRemoteL start"));
       
   892 
       
   893     TPtrC tmp;
       
   894     TInt ret;
       
   895     TInt tmpCmdType;
       
   896 
       
   897     // Set mode of item parser to be able to read titles with spaces inside
       
   898     iItem->SetParsingType(CStifItemParser::EQuoteStyleParsing);
       
   899 
       
   900     // Get and parse command
       
   901     ret = iItem->GetNextString( tmp );
       
   902     if( ret != KErrNone )
       
   903         {
       
   904         ERROR( _L("No command given") );
       
   905         User::Leave( KErrNotFound );
       
   906         }
       
   907 
       
   908     iCmdDes.Set( tmp );
       
   909     tmpCmdType = Parse( tmp, CmdType );
       
   910     RDebug::Print(_L("CStifTFwIfProt::ParseRemoteL readed command %d"), tmpCmdType);
       
   911     if( tmpCmdType < 0 )
       
   912         {
       
   913         iCmdType = ECmdUnknown;
       
   914         DEBUG( _L("Unknown command given") );        
       
   915         }
       
   916     else
       
   917     	{
       
   918     	iCmdType = ( TCmdType ) tmpCmdType;
       
   919     	}
       
   920         
       
   921     switch( iCmdType )
       
   922         {
       
   923         case ECmdRun:
       
   924             {
       
   925             RDebug::Print(_L("CStifTFwIfProt::ParseRemoteL iCmdType ECmdRun"));
       
   926             // Parse run parameters
       
   927             TPtrC arg; 
       
   928             TPtrC val;
       
   929             iTestCaseNumber = KErrNotFound;
       
   930             while( iItem->GetNextString( tmp ) == KErrNone )
       
   931                 {
       
   932                 if( ParseOptArg( tmp, arg, val ) == KErrNone )
       
   933                     {              
       
   934                     TInt param = Parse( arg, RunParams );
       
   935                     if( param < 0 )
       
   936                         {
       
   937                         ERROR( _L("Invalid run parameter given") );        
       
   938                         User::Leave( KErrArgument );
       
   939                         }
       
   940                     
       
   941                     switch( param )
       
   942                         {
       
   943                         case ERunModule:
       
   944                             iModule.Set( val );
       
   945                             break;
       
   946                         case ERunInifile:
       
   947                             iIniFile.Set( val );
       
   948                             break;
       
   949                         case ERunTestcasefile:
       
   950                             iTestCaseFile.Set( val );
       
   951                             break;
       
   952                         case ERunTestcasenum:
       
   953                             {
       
   954                             TLex ptr( val );
       
   955                             if( ptr.Val( iTestCaseNumber ) != KErrNone )
       
   956                                 {
       
   957                                 ERROR( _L("Invalid test case number given") );        
       
   958                                 User::Leave( KErrArgument );
       
   959                                 }  
       
   960                             }
       
   961                             break;
       
   962                         case ERunTitle:
       
   963                             iTitle.Set(val);
       
   964                             break;
       
   965                         default:
       
   966                             ERROR( _L("Invalid run parameter given") );        
       
   967                             User::Leave( KErrArgument );
       
   968                         }
       
   969                     }
       
   970                 else
       
   971                     {
       
   972                     ERROR( _L("Invalid run parameter given") );        
       
   973                     User::Leave( KErrArgument );
       
   974                     }
       
   975                 }
       
   976             if( iModule.Length() == 0 )
       
   977                 {
       
   978                 ERROR( _L("No mandatory test module name given as run parameter") );        
       
   979                 //User::Leave( KErrNotFound );
       
   980                 }    
       
   981             if(iTestCaseNumber < 0 && iTitle.Length() == 0) //No test case number and no title
       
   982                 {
       
   983                 ERROR( _L("No mandatory test case number given as run parameter") );        
       
   984                 //User::Leave( KErrNotFound );
       
   985                 }    
       
   986             }   
       
   987             break;
       
   988         case ECmdPause:
       
   989         case ECmdResume:
       
   990         case ECmdCancel:
       
   991             RDebug::Print(_L("CStifTFwIfProt::ParseRemoteL iCmdType ECmdPause,Resume,Cancel"));
       
   992             break;
       
   993         case ECmdRequest:
       
   994         case ECmdRelease:
       
   995             RDebug::Print(_L("CStifTFwIfProt::ParseRemoteL iCmdType ECmdRequest,Release"));
       
   996             ret = iItem->GetNextString( tmp );
       
   997             if( ret != KErrNone )
       
   998                 {
       
   999                 ERROR( _L("No event name given") );        
       
  1000                 //User::Leave( KErrNotFound );
       
  1001                 iEventName.Set( 0, 0 );
       
  1002                 }
       
  1003             else
       
  1004                 {
       
  1005                 iEventName.Set( tmp );
       
  1006                 }
       
  1007             break;
       
  1008         case ECmdSendReceive:
       
  1009             {
       
  1010             RDebug::Print(_L("CStifTFwIfProt::ParseRemoteL iCmdType ECmdSendReceive"));
       
  1011             DEBUG( _L("sendreceive") );
       
  1012             break;
       
  1013             }
       
  1014         default:
       
  1015             RDebug::Print(_L("CStifTFwIfProt::ParseRemoteL iCmdType UNKNOWN!!!"));
       
  1016             DEBUG( _L("Unknown command") );
       
  1017             break;
       
  1018         }
       
  1019     }    
       
  1020     
       
  1021 /*
       
  1022 -------------------------------------------------------------------------------
       
  1023 
       
  1024     Class: CStifTFwIfProt
       
  1025 
       
  1026     Method: ParseResponseL
       
  1027 
       
  1028     Description: Parse protocol response message.
       
  1029 
       
  1030     Parameters:	None
       
  1031     
       
  1032     Return Values: None.
       
  1033     
       
  1034     Errors/Exceptions: None.
       
  1035     
       
  1036     Status: Draft
       
  1037 	
       
  1038 -------------------------------------------------------------------------------
       
  1039 */
       
  1040 void CStifTFwIfProt::ParseResponseL()
       
  1041     {
       
  1042 
       
  1043     TPtrC tmp;
       
  1044     TInt ret;
       
  1045     TInt tmpRespType;
       
  1046     TInt tmpCmdType;
       
  1047 
       
  1048     // Get and parse request response type
       
  1049     ret = iItem->GetNextString( tmp );
       
  1050     if( ret != KErrNone )
       
  1051         {
       
  1052         ERROR( _L("No request type given") );
       
  1053         User::Leave( KErrNotFound );
       
  1054         }
       
  1055 
       
  1056     tmpRespType = Parse( tmp, MsgType );
       
  1057     if( tmpRespType < 0 )
       
  1058         {
       
  1059         ERROR( _L("Invalid request type given") );
       
  1060         User::Leave( KErrArgument );
       
  1061         }
       
  1062     else
       
  1063     	{
       
  1064     	iRespType = ( TMsgType ) tmpRespType;
       
  1065     	}
       
  1066 
       
  1067     ret = iItem->GetNextString( tmp );
       
  1068 
       
  1069     // First check if this is a response to a remote command
       
  1070     if( iRespType == EMsgRemote )
       
  1071         {
       
  1072         if( ret != KErrNone )
       
  1073             {
       
  1074             ERROR( _L("No arguments for remote response given") );
       
  1075             User::Leave( KErrNotFound );
       
  1076             }
       
  1077 
       
  1078         iCmdDes.Set( tmp );
       
  1079         tmpCmdType = Parse( tmp, CmdType );;
       
  1080         if( tmpCmdType >= 0 )
       
  1081             {
       
  1082 			iCmdType = ( TCmdType ) tmpCmdType;
       
  1083             DEBUG2( _L("Remote response for %S"), &tmp );
       
  1084             ParseCmdResponseL();
       
  1085             // Get and parse general response parameters
       
  1086             ret = iItem->GetNextString( tmp );
       
  1087             }
       
  1088         else
       
  1089             {
       
  1090             iCmdType = (TCmdType)KErrNotFound;
       
  1091             }
       
  1092         }
       
  1093     while( ret == KErrNone )
       
  1094         {
       
  1095         TPtrC arg;
       
  1096         TPtrC val;
       
  1097         if( ParseOptArg( tmp, arg, val ) == KErrNone )
       
  1098             {              
       
  1099             TInt param = Parse( arg, RespParam );
       
  1100             if( param < 0 )
       
  1101                 {
       
  1102                 ERROR( _L("Invalid parameter given") );        
       
  1103                 User::Leave( KErrArgument );
       
  1104                 }
       
  1105             
       
  1106             switch( param )
       
  1107                 {
       
  1108                 case ERespResult:
       
  1109                     {
       
  1110                     TLex ptr( val );
       
  1111                     if( ptr.Val( iResult ) != KErrNone )
       
  1112                         {
       
  1113                         ERROR( _L("Invalid error code given") );        
       
  1114                         User::Leave( KErrArgument );
       
  1115                         }   
       
  1116                     }
       
  1117                     break;
       
  1118                 default:
       
  1119                     ERROR( _L("Invalid parameter given") );        
       
  1120                     User::Leave( KErrArgument );
       
  1121                 }       
       
  1122             }
       
  1123 #if 0 // Check all parameters anyway
       
  1124         else 
       
  1125             {
       
  1126             ERROR( _L("Invalid parameter given") );        
       
  1127             User::Leave( KErrArgument ); 
       
  1128             }
       
  1129 #endif
       
  1130         ret = iItem->GetNextString( tmp );
       
  1131 
       
  1132         }
       
  1133     
       
  1134     }    
       
  1135     
       
  1136     
       
  1137 /*
       
  1138 -------------------------------------------------------------------------------
       
  1139 
       
  1140     Class: CStifTFwIfProt
       
  1141 
       
  1142     Method: ParseCmdResponseL
       
  1143 
       
  1144     Description: Parse protocol command response parameters.
       
  1145 
       
  1146     Parameters:	None
       
  1147     
       
  1148     Return Values: None.
       
  1149     
       
  1150     Errors/Exceptions: None.
       
  1151     
       
  1152     Status: Draft
       
  1153 	
       
  1154 -------------------------------------------------------------------------------
       
  1155 */
       
  1156 void CStifTFwIfProt::ParseCmdResponseL()
       
  1157     {
       
  1158     
       
  1159     TPtrC tmp;
       
  1160     TPtrC arg; 
       
  1161     TPtrC val;
       
  1162     TInt ret;
       
  1163     TInt tmpRunStatus;
       
  1164     TInt tmpResultCategory;
       
  1165     TInt tmpEventStatus;
       
  1166     TInt tmpEventType;	
       
  1167     
       
  1168     RDebug::Print(_L("CStifTFwIfProt::ParseCmdResponseL start"));
       
  1169     switch( iCmdType )
       
  1170         {
       
  1171         case ECmdRun:
       
  1172             {
       
  1173             RDebug::Print(_L("CStifTFwIfProt::ParseCmdResponseL ECmdRun"));
       
  1174             // Parse run response status 
       
  1175             ret = iItem->GetNextString( tmp );
       
  1176             if( ret != KErrNone )
       
  1177                 {
       
  1178                 ERROR( _L("No run response status given") );        
       
  1179                 User::Leave( KErrNotFound );
       
  1180                 }
       
  1181             
       
  1182             tmpRunStatus = Parse( tmp, RunStatus );;
       
  1183             if( tmpRunStatus < 0 )
       
  1184                 {
       
  1185                 ERROR( _L("Invalid run status in response given") );        
       
  1186                 User::Leave( KErrArgument );
       
  1187                 }
       
  1188             else
       
  1189             	{
       
  1190             	iRunStatus = (TRunStatus) tmpRunStatus;
       
  1191             	}
       
  1192             
       
  1193             // Parse runs status parameters
       
  1194             while( iItem->GetNextString( tmp ) == KErrNone )
       
  1195                 {
       
  1196                 if( ParseOptArg( tmp, arg, val ) == KErrNone )
       
  1197                     {              
       
  1198                     TInt param = Parse( arg, RunStatusParams );
       
  1199                     if( param < 0 )
       
  1200                         {
       
  1201                         ERROR( _L("Invalid run status parameter given") );        
       
  1202                         User::Leave( KErrArgument );
       
  1203                         }
       
  1204                     
       
  1205                     switch( param )
       
  1206                         {
       
  1207                         case ERunResult:
       
  1208                             {
       
  1209                             TLex ptr( val );
       
  1210                             if( ptr.Val( iResult ) != KErrNone )
       
  1211                                 {
       
  1212                                 ERROR( _L("Invalid run result given") );        
       
  1213                                 User::Leave( KErrArgument );
       
  1214                                 }  
       
  1215                             }
       
  1216                             break;
       
  1217                         case ERunCategory:
       
  1218                             tmpResultCategory = Parse( val, ResultCategory );
       
  1219                             if( tmpResultCategory < 0 )
       
  1220                                 {
       
  1221                                 ERROR( _L("Invalid run result category given") );        
       
  1222                                 User::Leave( KErrArgument );
       
  1223                                 }
       
  1224                             else 
       
  1225                             	{
       
  1226                             	iResultCategory = ( TResultCategory ) tmpResultCategory;
       
  1227                             	}
       
  1228                             break;
       
  1229                         default:
       
  1230                             ERROR( _L("Invalid run status parameter given") );        
       
  1231                             User::Leave( KErrArgument );
       
  1232                         }
       
  1233                     }
       
  1234                 else
       
  1235                     {
       
  1236                     ERROR( _L("Invalid run status parameter given") );        
       
  1237                     User::Leave( KErrArgument );                    
       
  1238                     }
       
  1239                 }
       
  1240             }           
       
  1241             break;
       
  1242         case ECmdPause:
       
  1243         case ECmdResume:
       
  1244         case ECmdCancel:
       
  1245             RDebug::Print(_L("CStifTFwIfProt::ParseCmdResponseL ECmdPause,Resume,Cancel"));
       
  1246             break;
       
  1247         case ECmdRequest:
       
  1248             {
       
  1249             RDebug::Print(_L("CStifTFwIfProt::ParseCmdResponseL ECmdRequest"));
       
  1250             // Parse event request response status
       
  1251             ret = iItem->GetNextString( tmp );
       
  1252             if( ret != KErrNone )
       
  1253                 {
       
  1254                 ERROR( _L("No request response status given") );        
       
  1255                 User::Leave( KErrNotFound );
       
  1256                 }
       
  1257             
       
  1258             tmpEventStatus = Parse( tmp, EventStatus );
       
  1259             if( tmpEventStatus < 0 )
       
  1260                 {
       
  1261                 ERROR( _L("Invalid request status in response given") );        
       
  1262                 User::Leave( KErrArgument );
       
  1263                 }
       
  1264             else
       
  1265             	{
       
  1266             	iEventStatus = (TEventStatus) tmpEventStatus;
       
  1267             	}
       
  1268             
       
  1269             // Parse request response event name
       
  1270             ret = iItem->GetNextString( tmp );
       
  1271             if( ret != KErrNone )
       
  1272                 {
       
  1273                 ERROR( _L("No request response event name given") );        
       
  1274                 User::Leave( KErrNotFound );
       
  1275                 }
       
  1276             iEventName.Set( tmp );    
       
  1277             
       
  1278             // Parse request response status parameters
       
  1279             while( iItem->GetNextString( tmp ) == KErrNone )
       
  1280                 {
       
  1281                 if( ParseOptArg( tmp, arg, val ) == KErrNone )
       
  1282                     {              
       
  1283                     TInt param = Parse( arg, EventStatusParams );
       
  1284                     if( param < 0 )
       
  1285                         {
       
  1286                         ERROR( _L("Invalid request response status parameter given") );        
       
  1287                         User::Leave( KErrArgument );
       
  1288                         }
       
  1289                     
       
  1290                     switch( param )
       
  1291                         {
       
  1292                         case EEventResult:
       
  1293                             {
       
  1294                             TLex ptr( val );
       
  1295                             if( ptr.Val( iResult ) != KErrNone )
       
  1296                                 {
       
  1297                                 ERROR( _L("Invalid request response status parameter result given") );        
       
  1298                                 User::Leave( KErrArgument );
       
  1299                                 }  
       
  1300                             }
       
  1301                             break;
       
  1302                         case EEventType:
       
  1303                             tmpEventType = Parse( val, EventType );;
       
  1304                             if( tmpEventType < 0 )
       
  1305                                 {
       
  1306                                 ERROR( _L("Invalid request response status parameter event type given") );        
       
  1307                                 User::Leave( KErrArgument );
       
  1308                                 }
       
  1309                             else
       
  1310                             	{
       
  1311                             	iEventType = ( TEventIf::TEventType ) tmpEventType;
       
  1312                             	}
       
  1313                             break;
       
  1314                         default:
       
  1315                             ERROR( _L("Invalid request response status parameter given") );        
       
  1316                             User::Leave( KErrArgument );
       
  1317                         }
       
  1318                     }
       
  1319                 else
       
  1320                     {
       
  1321                     ERROR( _L("Invalid request response status parameter given") );        
       
  1322                     User::Leave( KErrArgument );            
       
  1323                     }    
       
  1324                 }
       
  1325             }
       
  1326             break;
       
  1327         case ECmdRelease:
       
  1328             RDebug::Print(_L("CStifTFwIfProt::ParseCmdResponseL ECmdRelease"));
       
  1329             // Parse release response event name
       
  1330             ret = iItem->GetNextString( tmp );
       
  1331             if( ret != KErrNone )
       
  1332                 {
       
  1333                 ERROR( _L("No release response event name given") );        
       
  1334                 User::Leave( KErrNotFound );
       
  1335                 }
       
  1336             iEventName.Set( tmp );    
       
  1337             break;
       
  1338         case ECmdSetEvent:
       
  1339         case ECmdUnsetEvent:
       
  1340             RDebug::Print(_L("CStifTFwIfProt::ParseCmdResponseL ECmdSetEvent,UnsetEvent"));
       
  1341             // Parse release response event name
       
  1342             ret = iItem->GetNextString( tmp );
       
  1343             if( ret != KErrNone )
       
  1344                 {
       
  1345                 ERROR( _L("No set/unset response event name given") );
       
  1346                 User::Leave( KErrNotFound );
       
  1347                 }
       
  1348             iEventName.Set( tmp );
       
  1349             break;
       
  1350         case ECmdSendReceive:
       
  1351             {
       
  1352             RDebug::Print(_L("CStifTFwIfProt::ParseCmdResponseL ECmdSendReceive"));
       
  1353             // Parse sendreceive response status
       
  1354             ret = iItem->GetNextString( tmp );
       
  1355             if( ret != KErrNone )
       
  1356                 {
       
  1357                 ERROR( _L("No run response status given") );        
       
  1358                 User::Leave( KErrNotFound );
       
  1359                 }
       
  1360             
       
  1361             tmpRunStatus = Parse( tmp, RunStatus );
       
  1362             if( tmpRunStatus < 0 )
       
  1363                 {
       
  1364                 ERROR( _L("Invalid run status in response given") );        
       
  1365                 User::Leave( KErrArgument );
       
  1366                 }
       
  1367             else
       
  1368             	{
       
  1369             	iRunStatus = (TRunStatus) tmpRunStatus;
       
  1370             	}
       
  1371             break;
       
  1372             }
       
  1373         default:
       
  1374             ERROR( _L("Invalid command response") );        
       
  1375             User::Leave( KErrArgument );
       
  1376         
       
  1377         }      
       
  1378     }
       
  1379     
       
  1380     
       
  1381 /*
       
  1382 -------------------------------------------------------------------------------
       
  1383 
       
  1384      Class: CStifTFwIfProt
       
  1385 
       
  1386      Method: MsgType
       
  1387 
       
  1388      Description: Returns a string desrciptor corresponding 
       
  1389         to message type number. 
       
  1390 
       
  1391      Parameters:    TInt aKeyword: in: keyword index.
       
  1392      
       
  1393      Return Values: TPtrC: keyword descriptor
       
  1394 
       
  1395      Errors/Exceptions: None
       
  1396      
       
  1397      Status: Draft 
       
  1398     
       
  1399 -------------------------------------------------------------------------------
       
  1400 */      
       
  1401 EXPORT_C TPtrC CStifTFwIfProt::MsgType( TInt aKeyword )
       
  1402     {
       
  1403     static TText* const keywords[] =
       
  1404         {
       
  1405         (TText*)L"reserve",
       
  1406         (TText*)L"release",
       
  1407         (TText*)L"remote",
       
  1408         (TText*)L"response",
       
  1409         };
       
  1410     
       
  1411     if( (TUint)aKeyword >= (sizeof( keywords )/sizeof(TText*)) )
       
  1412           {
       
  1413           TPtrC null;
       
  1414           return null;
       
  1415           } 
       
  1416     
       
  1417     TPtrC keyword( keywords[ aKeyword ] ); 
       
  1418     return keyword;
       
  1419     
       
  1420     }
       
  1421     
       
  1422 /*
       
  1423 -------------------------------------------------------------------------------
       
  1424 
       
  1425      Class: CStifTFwIfProt
       
  1426 
       
  1427      Method: ResultCategory
       
  1428 
       
  1429      Description: Returns a string desrciptor corresponding 
       
  1430         to result category number. 
       
  1431 
       
  1432      Parameters:    TInt aKeyword: in: keyword index.
       
  1433      
       
  1434      Return Values: TPtrC: keyword descriptor
       
  1435 
       
  1436      Errors/Exceptions: None
       
  1437      
       
  1438      Status: Draft 
       
  1439     
       
  1440 -------------------------------------------------------------------------------
       
  1441 */      
       
  1442 EXPORT_C TPtrC CStifTFwIfProt::CmdType( TInt aKeyword )
       
  1443     {
       
  1444     static TText* const keywords[] =
       
  1445         {
       
  1446         (TText*)L"run",
       
  1447         (TText*)L"pause",
       
  1448         (TText*)L"resume",
       
  1449         (TText*)L"cancel",
       
  1450         (TText*)L"request",
       
  1451         (TText*)L"release",
       
  1452         (TText*)L"sendreceive",
       
  1453         (TText*)L"set",
       
  1454         (TText*)L"unset",
       
  1455         };
       
  1456     
       
  1457     if( (TUint)aKeyword >= (sizeof( keywords )/sizeof(TText*)) )
       
  1458           {
       
  1459           TPtrC null;
       
  1460           return null;
       
  1461           } 
       
  1462     
       
  1463     TPtrC keyword( keywords[ aKeyword ] ); 
       
  1464     return keyword;
       
  1465     
       
  1466     }
       
  1467     
       
  1468 /*
       
  1469 -------------------------------------------------------------------------------
       
  1470 
       
  1471      Class: CStifTFwIfProt
       
  1472 
       
  1473      Method: RemoteType
       
  1474 
       
  1475      Description: Returns a string desrciptor corresponding 
       
  1476         to remote type number. 
       
  1477 
       
  1478      Parameters:    TInt aKeyword: in: keyword index.
       
  1479      
       
  1480      Return Values: TPtrC: keyword descriptor
       
  1481 
       
  1482      Errors/Exceptions: None
       
  1483      
       
  1484      Status: Draft 
       
  1485     
       
  1486 -------------------------------------------------------------------------------
       
  1487 */      
       
  1488 EXPORT_C TPtrC CStifTFwIfProt::RemoteType( TInt aKeyword )
       
  1489     {
       
  1490     static TText* const keywords[] =
       
  1491         {
       
  1492         (TText*)L"phone",
       
  1493         };
       
  1494     
       
  1495     if( (TUint)aKeyword >= (sizeof( keywords )/sizeof(TText*)) )
       
  1496           {
       
  1497           TPtrC null;
       
  1498           return null;
       
  1499           } 
       
  1500     
       
  1501     TPtrC keyword( keywords[ aKeyword ] ); 
       
  1502     return keyword;
       
  1503     
       
  1504     }
       
  1505     
       
  1506 /*
       
  1507 -------------------------------------------------------------------------------
       
  1508 
       
  1509      Class: CStifTFwIfProt
       
  1510 
       
  1511      Method: RunParams
       
  1512 
       
  1513      Description: Returns a string desrciptor corresponding 
       
  1514         to run parameter number. 
       
  1515 
       
  1516      Parameters:    TInt aKeyword: in: keyword index.
       
  1517      
       
  1518      Return Values: TPtrC: keyword descriptor
       
  1519 
       
  1520      Errors/Exceptions: None
       
  1521      
       
  1522      Status: Draft 
       
  1523     
       
  1524 -------------------------------------------------------------------------------
       
  1525 */      
       
  1526 EXPORT_C TPtrC CStifTFwIfProt::RunParams( TInt aKeyword )
       
  1527     {
       
  1528     static TText* const keywords[] =
       
  1529         {
       
  1530         (TText*)L"module",
       
  1531         (TText*)L"inifile",
       
  1532         (TText*)L"testcasefile",
       
  1533         (TText*)L"testcasenum",
       
  1534         (TText*)L"title",
       
  1535         };
       
  1536     
       
  1537     if( (TUint)aKeyword >= (sizeof( keywords )/sizeof(TText*)) )
       
  1538           {
       
  1539           TPtrC null;
       
  1540           return null;
       
  1541           } 
       
  1542     
       
  1543     TPtrC keyword( keywords[ aKeyword ] ); 
       
  1544     return keyword;
       
  1545     
       
  1546     }
       
  1547   
       
  1548 /*
       
  1549 -------------------------------------------------------------------------------
       
  1550 
       
  1551      Class: CStifTFwIfProt
       
  1552 
       
  1553      Method: RunStatus
       
  1554 
       
  1555      Description: Returns a string desrciptor corresponding 
       
  1556         to run status number. 
       
  1557 
       
  1558      Parameters:    TInt aKeyword: in: keyword index.
       
  1559      
       
  1560      Return Values: TPtrC: keyword descriptor
       
  1561 
       
  1562      Errors/Exceptions: None
       
  1563      
       
  1564      Status: Draft 
       
  1565     
       
  1566 -------------------------------------------------------------------------------
       
  1567 */      
       
  1568 EXPORT_C TPtrC CStifTFwIfProt::RunStatus( TInt aKeyword )
       
  1569     {
       
  1570     static TText* const keywords[] =
       
  1571         {
       
  1572         (TText*)L"started",
       
  1573         (TText*)L"error",
       
  1574         (TText*)L"ready",
       
  1575         };
       
  1576     
       
  1577     if( (TUint)aKeyword >= (sizeof( keywords )/sizeof(TText*)) )
       
  1578           {
       
  1579           TPtrC null;
       
  1580           return null;
       
  1581           } 
       
  1582     
       
  1583     TPtrC keyword( keywords[ aKeyword ] ); 
       
  1584     return keyword;
       
  1585     
       
  1586     }
       
  1587 
       
  1588 /*
       
  1589 -------------------------------------------------------------------------------
       
  1590 
       
  1591      Class: CStifTFwIfProt
       
  1592 
       
  1593      Method: RunStatusParams
       
  1594 
       
  1595      Description: Returns a string desrciptor corresponding 
       
  1596         to run status parameter number. 
       
  1597 
       
  1598      Parameters:    TInt aKeyword: in: keyword index.
       
  1599      
       
  1600      Return Values: TPtrC: keyword descriptor
       
  1601 
       
  1602      Errors/Exceptions: None
       
  1603      
       
  1604      Status: Draft 
       
  1605     
       
  1606 -------------------------------------------------------------------------------
       
  1607 */      
       
  1608 EXPORT_C TPtrC CStifTFwIfProt::RunStatusParams( TInt aKeyword )
       
  1609     {
       
  1610     static TText* const keywords[] =
       
  1611         {
       
  1612         (TText*)L"result",
       
  1613         (TText*)L"category",
       
  1614         };
       
  1615     
       
  1616     if( (TUint)aKeyword >= (sizeof( keywords )/sizeof(TText*)) )
       
  1617           {
       
  1618           TPtrC null;
       
  1619           return null;
       
  1620           } 
       
  1621     
       
  1622     TPtrC keyword( keywords[ aKeyword ] ); 
       
  1623     return keyword;
       
  1624     
       
  1625     }
       
  1626     
       
  1627 /*
       
  1628 -------------------------------------------------------------------------------
       
  1629 
       
  1630      Class: CStifTFwIfProt
       
  1631 
       
  1632      Method: ResultCategory
       
  1633 
       
  1634      Description: Returns a string desrciptor corresponding 
       
  1635         to command type number. 
       
  1636 
       
  1637      Parameters:    TInt aKeyword: in: keyword index.
       
  1638      
       
  1639      Return Values: TPtrC: keyword descriptor
       
  1640 
       
  1641      Errors/Exceptions: None
       
  1642      
       
  1643      Status: Draft 
       
  1644     
       
  1645 -------------------------------------------------------------------------------
       
  1646 */      
       
  1647 EXPORT_C TPtrC CStifTFwIfProt::ResultCategory( TInt aKeyword )
       
  1648     {
       
  1649     static TText* const keywords[] =
       
  1650         {
       
  1651         (TText*)L"normal",
       
  1652         (TText*)L"panic",
       
  1653         (TText*)L"exception",
       
  1654         (TText*)L"timeout",
       
  1655         (TText*)L"leave",
       
  1656         };
       
  1657     
       
  1658     if( (TUint)aKeyword >= (sizeof( keywords )/sizeof(TText*)) )
       
  1659           {
       
  1660           TPtrC null;
       
  1661           return null;
       
  1662           } 
       
  1663     
       
  1664     TPtrC keyword( keywords[ aKeyword ] ); 
       
  1665     return keyword;
       
  1666     
       
  1667     }
       
  1668     
       
  1669 /*
       
  1670 -------------------------------------------------------------------------------
       
  1671 
       
  1672      Class: CStifTFwIfProt
       
  1673 
       
  1674      Method: EventStatus
       
  1675 
       
  1676      Description: Returns a string desrciptor corresponding 
       
  1677         to command type number. 
       
  1678 
       
  1679      Parameters:    TInt aKeyword: in: keyword index.
       
  1680      
       
  1681      Return Values: TPtrC: keyword descriptor
       
  1682 
       
  1683      Errors/Exceptions: None
       
  1684      
       
  1685      Status: Draft 
       
  1686     
       
  1687 -------------------------------------------------------------------------------
       
  1688 */      
       
  1689 EXPORT_C TPtrC CStifTFwIfProt::EventStatus( TInt aKeyword )
       
  1690     {
       
  1691     static TText* const keywords[] =
       
  1692         {
       
  1693         (TText*)L"active",
       
  1694         (TText*)L"set",
       
  1695         (TText*)L"error",
       
  1696         };
       
  1697     
       
  1698     if( (TUint)aKeyword >= (sizeof( keywords )/sizeof(TText*)) )
       
  1699           {
       
  1700           TPtrC null;
       
  1701           return null;
       
  1702           } 
       
  1703     
       
  1704     TPtrC keyword( keywords[ aKeyword ] ); 
       
  1705     return keyword;
       
  1706     
       
  1707     }
       
  1708     
       
  1709 /*
       
  1710 -------------------------------------------------------------------------------
       
  1711 
       
  1712      Class: CStifTFwIfProt
       
  1713 
       
  1714      Method: EventStatusParams
       
  1715 
       
  1716      Description: Returns a string desrciptor corresponding 
       
  1717         to command type number. 
       
  1718 
       
  1719      Parameters:    TInt aKeyword: in: keyword index.
       
  1720      
       
  1721      Return Values: TPtrC: keyword descriptor
       
  1722 
       
  1723      Errors/Exceptions: None
       
  1724      
       
  1725      Status: Draft 
       
  1726     
       
  1727 -------------------------------------------------------------------------------
       
  1728 */      
       
  1729 EXPORT_C TPtrC CStifTFwIfProt::EventStatusParams( TInt aKeyword )
       
  1730     {
       
  1731     static TText* const keywords[] =
       
  1732         {
       
  1733         (TText*)L"result",
       
  1734         (TText*)L"type",
       
  1735         };
       
  1736     
       
  1737     if( (TUint)aKeyword >= (sizeof( keywords )/sizeof(TText*)) )
       
  1738           {
       
  1739           TPtrC null;
       
  1740           return null;
       
  1741           } 
       
  1742     
       
  1743     TPtrC keyword( keywords[ aKeyword ] ); 
       
  1744     return keyword;
       
  1745     
       
  1746     }
       
  1747     
       
  1748 /*
       
  1749 -------------------------------------------------------------------------------
       
  1750 
       
  1751      Class: CStifTFwIfProt
       
  1752 
       
  1753      Method: EventType
       
  1754 
       
  1755      Description: Returns a string desrciptor corresponding 
       
  1756         to event type number. 
       
  1757 
       
  1758      Parameters:    TInt aKeyword: in: keyword index.
       
  1759      
       
  1760      Return Values: TPtrC: keyword descriptor
       
  1761 
       
  1762      Errors/Exceptions: None
       
  1763      
       
  1764      Status: Draft 
       
  1765     
       
  1766 -------------------------------------------------------------------------------
       
  1767 */      
       
  1768 EXPORT_C TPtrC CStifTFwIfProt::EventType( TInt aKeyword )
       
  1769     {
       
  1770     static TText* const keywords[] =
       
  1771         {
       
  1772         (TText*)L"indication",
       
  1773         (TText*)L"state",
       
  1774         };
       
  1775     
       
  1776     if( (TUint)aKeyword >= (sizeof( keywords )/sizeof(TText*)) )
       
  1777           {
       
  1778           TPtrC null;
       
  1779           return null;
       
  1780           } 
       
  1781     
       
  1782     TPtrC keyword( keywords[ aKeyword ] ); 
       
  1783     return keyword;
       
  1784     
       
  1785     }
       
  1786     
       
  1787 /*
       
  1788 -------------------------------------------------------------------------------
       
  1789 
       
  1790      Class: CStifTFwIfProt
       
  1791 
       
  1792      Method: RespParam
       
  1793 
       
  1794      Description: Returns a string desrciptor corresponding 
       
  1795         to response parameter number. 
       
  1796 
       
  1797      Parameters:    TInt aKeyword: in: keyword index.
       
  1798      
       
  1799      Return Values: TPtrC: keyword descriptor
       
  1800 
       
  1801      Errors/Exceptions: None
       
  1802      
       
  1803      Status: Draft 
       
  1804     
       
  1805 -------------------------------------------------------------------------------
       
  1806 */      
       
  1807 EXPORT_C TPtrC CStifTFwIfProt::RespParam( TInt aKeyword )
       
  1808     {
       
  1809     static TText* const keywords[] =
       
  1810         {
       
  1811         (TText*)L"result",
       
  1812         };
       
  1813     
       
  1814     if( (TUint)aKeyword >= (sizeof( keywords )/sizeof(TText*)) )
       
  1815           {
       
  1816           TPtrC null;
       
  1817           return null;
       
  1818           } 
       
  1819     
       
  1820     TPtrC keyword( keywords[ aKeyword ] ); 
       
  1821     return keyword;
       
  1822     
       
  1823     }
       
  1824 
       
  1825 
       
  1826 /*
       
  1827 -------------------------------------------------------------------------------
       
  1828 
       
  1829      Class: CStifTFwIfProt
       
  1830 
       
  1831      Method: SetSrcId
       
  1832 
       
  1833      Description: Set protocol source identifier.
       
  1834 
       
  1835      Parameters: TUint32 aSrcId: in: source identifier
       
  1836      
       
  1837      Return Values: Symbian OS error code
       
  1838 
       
  1839      Errors/Exceptions: None
       
  1840      
       
  1841      Status: Draft 
       
  1842     
       
  1843 -------------------------------------------------------------------------------
       
  1844 */
       
  1845 EXPORT_C TInt CStifTFwIfProt::SetSrcId( TUint32 aSrcId )
       
  1846     {
       
  1847     
       
  1848     iSrcId = aSrcId;
       
  1849     return AppendId( iSrcId );
       
  1850     
       
  1851     }
       
  1852     
       
  1853 /*
       
  1854 -------------------------------------------------------------------------------
       
  1855 
       
  1856      Class: CStifTFwIfProt
       
  1857 
       
  1858      Method: SetDstId
       
  1859 
       
  1860      Description: Set protocol destination identifier.
       
  1861 
       
  1862      Parameters: TUint32 aDstId: in: destination identifier
       
  1863      
       
  1864      Return Values: Symbian OS error code
       
  1865 
       
  1866      Errors/Exceptions: None
       
  1867      
       
  1868      Status: Draft 
       
  1869     
       
  1870 -------------------------------------------------------------------------------
       
  1871 */ 
       
  1872 EXPORT_C TInt CStifTFwIfProt::SetDstId( TUint32 aDstId )
       
  1873     {
       
  1874     
       
  1875     iDstId = aDstId;
       
  1876     return AppendId( iDstId );
       
  1877     
       
  1878     }
       
  1879     
       
  1880 
       
  1881 /*
       
  1882 -------------------------------------------------------------------------------
       
  1883 
       
  1884      Class: CStifTFwIfProt
       
  1885 
       
  1886      Method: SetMsgType
       
  1887 
       
  1888      Description: Set message type.
       
  1889 
       
  1890      Parameters: TMsgType iMsgType: in: message type
       
  1891      
       
  1892      Return Values: Symbian OS error code
       
  1893 
       
  1894      Errors/Exceptions: None
       
  1895      
       
  1896      Status: Draft 
       
  1897     
       
  1898 -------------------------------------------------------------------------------
       
  1899 */ 
       
  1900 EXPORT_C TInt CStifTFwIfProt::SetMsgType( TMsgType aMsgType )
       
  1901     {
       
  1902     
       
  1903     iMsgType = aMsgType;
       
  1904     return Append( CStifTFwIfProt::MsgType, iMsgType );
       
  1905     
       
  1906     }
       
  1907     
       
  1908 
       
  1909 /*
       
  1910 -------------------------------------------------------------------------------
       
  1911 
       
  1912      Class: CStifTFwIfProt
       
  1913 
       
  1914      Method: SetRespType
       
  1915 
       
  1916      Description: Set response type.
       
  1917 
       
  1918      Parameters:    TMsgType iMsgType : in: set response type
       
  1919      
       
  1920      Return Values: Symbian OS error code
       
  1921      
       
  1922      Errors/Exceptions: None
       
  1923      
       
  1924      Status: Draft 
       
  1925     
       
  1926 -------------------------------------------------------------------------------
       
  1927 */ 
       
  1928 EXPORT_C TInt CStifTFwIfProt::SetRespType( TMsgType aRespType )
       
  1929     {
       
  1930     
       
  1931     iRespType = aRespType;
       
  1932     return Append( CStifTFwIfProt::MsgType, iRespType );
       
  1933     
       
  1934     }
       
  1935     
       
  1936 /*
       
  1937 -------------------------------------------------------------------------------
       
  1938 
       
  1939      Class: CStifTFwIfProt
       
  1940 
       
  1941      Method: SetCmdType
       
  1942 
       
  1943      Description: Set command type.
       
  1944 
       
  1945      Parameters: TCmdType iCmdType: in: command type
       
  1946      
       
  1947      Return Values: None
       
  1948 
       
  1949      Errors/Exceptions: None
       
  1950      
       
  1951      Status: Draft 
       
  1952     
       
  1953 -------------------------------------------------------------------------------
       
  1954 */
       
  1955 EXPORT_C TInt CStifTFwIfProt::SetCmdType( TCmdType aCmdType )
       
  1956     {
       
  1957     
       
  1958     iCmdType = aCmdType;
       
  1959     return Append( CStifTFwIfProt::CmdType, iCmdType );
       
  1960     
       
  1961     }
       
  1962 
       
  1963     
       
  1964 /*
       
  1965 -------------------------------------------------------------------------------
       
  1966 
       
  1967      Class: CStifTFwIfProt
       
  1968 
       
  1969      Method: Parse
       
  1970 
       
  1971      Description: Returns a keyword enum corresponding to keyword 
       
  1972                   string descriptor.
       
  1973 
       
  1974      Parameters:    TPtrC aKeyword: in: keyword descriptor.
       
  1975                     KeywordFunc aFunc: in: Function pointer to keyword parser 
       
  1976      
       
  1977      Return Values: TInt: keyword index
       
  1978                     KErrNotFound: Keyword does not exists
       
  1979 
       
  1980      Errors/Exceptions: None
       
  1981      
       
  1982      Status: Draft 
       
  1983     
       
  1984 ------------------------------------------------------------------------------
       
  1985 */
       
  1986 TInt CStifTFwIfProt::Parse( TDesC& aKeyword, KeywordFunc aFunc )
       
  1987     {
       
  1988     TInt ind;
       
  1989     for( ind = 0; aFunc( ind ).Length() > 0; ind++ )
       
  1990         {
       
  1991         if( aFunc( ind ) == aKeyword )
       
  1992             {
       
  1993             return ind;
       
  1994             }
       
  1995         }
       
  1996     return KErrNotFound;
       
  1997     };
       
  1998     
       
  1999     
       
  2000     /*
       
  2001 -------------------------------------------------------------------------------
       
  2002 
       
  2003      Class: CStifTFwIfProt
       
  2004 
       
  2005      Method: ParseOptArgL
       
  2006 
       
  2007      Description: Parses optional argument 
       
  2008   
       
  2009      Parameters: const TDesC& aOptArg: in: 
       
  2010                     argument-value pair (format arg=value)
       
  2011                  TPtrC& aArg: out: parsed argument  
       
  2012                  TPtrC& aVal: out: parsed value
       
  2013      
       
  2014      Return Values: KErrNone: Everything ok
       
  2015                     Symbian OS error code: Not a valid optarg
       
  2016 
       
  2017      Errors/Exceptions: None
       
  2018 
       
  2019      Status: Draft
       
  2020     
       
  2021 -------------------------------------------------------------------------------
       
  2022 */
       
  2023 TInt CStifTFwIfProt::ParseOptArg( const TDesC& aOptArg, 
       
  2024                                    TPtrC& aArg, 
       
  2025                                    TPtrC& aVal )
       
  2026     { 
       
  2027     TInt length = aOptArg.Length();
       
  2028     for( TInt i=0; i < length; i++) 
       
  2029         {
       
  2030         // find the '=' sign 
       
  2031         if( aOptArg[i] == '=' )
       
  2032             {
       
  2033             if( i+1 >= length )
       
  2034                 {
       
  2035                 return KErrArgument;
       
  2036                 }
       
  2037             aArg.Set( aOptArg.Left( i ) );
       
  2038             aVal.Set( aOptArg.Mid( i+1 ) );
       
  2039             DEBUG3(  _L( "arg '%S', val '%S'" ),
       
  2040                 &aArg, &aVal );        
       
  2041             return KErrNone;
       
  2042             }
       
  2043         }
       
  2044     return KErrArgument;
       
  2045     
       
  2046     }     
       
  2047 
       
  2048 // ================= OTHER EXPORTED FUNCTIONS =================================
       
  2049 // None
       
  2050 
       
  2051 // End of File