telephonyserverplugins/simatktsy/src/CSatNotifySetUpIdleModeText.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
child 42 3adadc800673
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2005-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 // Name        : CSatNotifySetUpIdleModeText.cpp
       
    15 // Part of     : Common SIM ATK TSY / commonsimatktsy
       
    16 // SetUpIdleModeText notification functionality of Sat Tsy
       
    17 // Version     : 1.0
       
    18 //
       
    19 
       
    20 
       
    21 
       
    22 //INCLUDES
       
    23 #include <satcs.h>						// Etel SAT IPC definitions
       
    24 #include "CSatTsy.h"					// Tsy class header
       
    25 #include "CSatNotifySetUpIdleModeText.h"// Tsy class header
       
    26 #include "CSatNotificationsTsy.h"		// Class header
       
    27 #include "CBerTlv.h"					// Ber Tlv data handling
       
    28 #include "TTlv.h"						// TTlv class
       
    29 #include "CSatDataPackage.h"			// Parameter packing 
       
    30 #include "TfLogger.h"					// For TFLOGSTRING
       
    31 #include "TSatUtility.h"				// Utilities
       
    32 #include "CSatTsyReqHandleStore.h"		// Request handle class
       
    33 #include "cmmmessagemanagerbase.h"		// Message manager class for forwarding req.
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CSatNotifySetUpIdleModeText::NewL
       
    37 // Two-phased constructor.
       
    38 // -----------------------------------------------------------------------------
       
    39 //  
       
    40 CSatNotifySetUpIdleModeText* CSatNotifySetUpIdleModeText::NewL
       
    41         ( 
       
    42         CSatNotificationsTsy* aNotificationsTsy 
       
    43         )
       
    44     {
       
    45     TFLOGSTRING("CSAT: CSatNotifySetUpIdleModeText::NewL");
       
    46    	CSatNotifySetUpIdleModeText* const satNotifySetUpIdleModeText = 
       
    47         new ( ELeave ) CSatNotifySetUpIdleModeText( aNotificationsTsy );
       
    48     CleanupStack::PushL( satNotifySetUpIdleModeText );
       
    49     satNotifySetUpIdleModeText->ConstructL();
       
    50     CleanupStack::Pop( satNotifySetUpIdleModeText );
       
    51     TFLOGSTRING("CSAT: CSatNotifySetUpIdleModeText::NewL, end of method");
       
    52     return satNotifySetUpIdleModeText;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CSatNotifySetUpIdleModeText::~CSatNotifySetUpIdleModeText
       
    57 // Destructor
       
    58 // -----------------------------------------------------------------------------
       
    59 //  
       
    60 CSatNotifySetUpIdleModeText::~CSatNotifySetUpIdleModeText
       
    61         ( 
       
    62 		// None
       
    63         )
       
    64     {
       
    65     TFLOGSTRING("CSAT: CSatNotifySetUpIdleModeText::\
       
    66         ~CSatNotifySetUpIdleModeText");
       
    67     }
       
    68     
       
    69 // -----------------------------------------------------------------------------
       
    70 // CSatNotifySetUpIdleModeText::CSatNotifySetUpIdleModeText
       
    71 // Default C++ constructor
       
    72 // -----------------------------------------------------------------------------
       
    73 //  
       
    74 CSatNotifySetUpIdleModeText::CSatNotifySetUpIdleModeText
       
    75         ( 
       
    76         CSatNotificationsTsy* aNotificationsTsy 
       
    77         ) : iNotificationsTsy ( aNotificationsTsy )
       
    78     {
       
    79     // None
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CSatNotifySetUpIdleModeText::ConstructL
       
    84 // Symbian 2nd phase constructor
       
    85 // -----------------------------------------------------------------------------
       
    86 //  
       
    87 void CSatNotifySetUpIdleModeText::ConstructL
       
    88         (
       
    89         // None
       
    90         )
       
    91     {
       
    92     TFLOGSTRING("CSAT: CSatNotifySetUpIdleModeText::ConstructL");
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CSatNotifySetUpIdleModeText::Notify
       
    97 // This request allows a client to be notified of a Set Up Idle Mode Text 
       
    98 // proactive command
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 TInt CSatNotifySetUpIdleModeText::Notify
       
   102         (
       
   103         const TTsyReqHandle aTsyReqHandle,
       
   104         const TDataPackage& aPackage    
       
   105         )
       
   106     {
       
   107     TFLOGSTRING("CSAT: CSatNotifySetUpIdleModeText::Notify");
       
   108     // Save data pointer to client side for completion
       
   109     iSetUpIdleModeTextV1Pckg = reinterpret_cast<RSat::
       
   110     	TSetUpIdleModeTextV1Pckg*>( aPackage.Des1n() );
       
   111     // Save the request handle
       
   112     iNotificationsTsy->iSatTsy->SaveReqHandle( aTsyReqHandle, 
       
   113 		CSatTsy::ESatNotifySetUpIdleModeTextPCmdReqType );
       
   114     // Check if requested notification is already pending
       
   115     iNotificationsTsy->NotifySatReadyForNotification( KSetUpIdleModeText );   
       
   116 
       
   117     return KErrNone;
       
   118 
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CSatNotifySetUpIdleModeText::CancelNotification
       
   123 // This method cancels an outstanding asynchronous 
       
   124 // NotifySetUpIdleModeText request.
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 TInt CSatNotifySetUpIdleModeText::CancelNotification
       
   128         (
       
   129         const TTsyReqHandle aTsyReqHandle
       
   130         )
       
   131     {
       
   132     TFLOGSTRING("CSAT: CSatNotifySetUpIdleModeText::CancelNotification");
       
   133     
       
   134     // Reset the request handle
       
   135     TTsyReqHandle reqHandle = iNotificationsTsy->iSatReqHandleStore->
       
   136         ResetTsyReqHandle( CSatTsy::ESatNotifySetUpIdleModeTextPCmdReqType );
       
   137 	// Reset the data pointer
       
   138 	iSetUpIdleModeTextV1Pckg = NULL;
       
   139 	// Complete the request with KErrCancel
       
   140 	iNotificationsTsy->iSatTsy->ReqCompleted( aTsyReqHandle, KErrCancel );
       
   141 
       
   142     return KErrNone;    
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CSatNotifySetUpIdleModeText::CompleteNotifyL
       
   147 // This method completes an outstanding asynchronous 
       
   148 // NotifySetUpIdleModeText request. 
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 TInt CSatNotifySetUpIdleModeText::CompleteNotifyL
       
   152         (
       
   153         CSatDataPackage* aDataPackage,  
       
   154         TInt aErrorCode                  
       
   155         )
       
   156     {   
       
   157 	TFLOGSTRING("CSAT: CSatNotifySetUpIdleModeText::CompleteNotifyL");
       
   158     TInt ret( KErrNone );
       
   159 	TInt returnValue( KErrNone );
       
   160 	TBuf<1> additionalInfo;	
       
   161     // Unpack parameters
       
   162     TPtrC8* data;
       
   163     aDataPackage->UnPackData( &data );
       
   164     // Reset req handle. Returns the deleted req handle
       
   165     TTsyReqHandle reqHandle = 
       
   166 		iNotificationsTsy->iSatReqHandleStore->ResetTsyReqHandle( 
       
   167         CSatTsy::ESatNotifySetUpIdleModeTextPCmdReqType );
       
   168 	// Get ber tlv 
       
   169     CBerTlv berTlv;
       
   170     berTlv.SetData( *data );
       
   171 	//get command details tlv
       
   172 	CTlv commandDetails;
       
   173 	berTlv.TlvByTagValue( &commandDetails, KTlvCommandDetailsTag );	
       
   174 	// Store command details tlv
       
   175 	iNotificationsTsy->iTerminalRespData.iCommandDetails.Copy( 
       
   176 		commandDetails.Data() );
       
   177 	TUint8 pCmdNumber( commandDetails.GetShortInfo( ETLV_CommandNumber ) );
       
   178 	
       
   179 	// In case the request was ongoing, continue..
       
   180     if ( CSatTsy::ESatReqHandleUnknown != reqHandle )
       
   181         {
       
   182         // Complete right away if error has occured, otherwise continue..
       
   183         if ( KErrNone == aErrorCode )
       
   184             {
       
   185 			// Fill the set up idle mode text structure
       
   186 			RSat::TSetUpIdleModeTextV1& setUpIdleModeTextV1 
       
   187 				= ( *iSetUpIdleModeTextV1Pckg )();
       
   188 
       
   189 			// Store command number
       
   190             setUpIdleModeTextV1.SetPCmdNumber( pCmdNumber );
       
   191 			
       
   192 			//Initialize Type to notSet and text to zero
       
   193 			setUpIdleModeTextV1.iType = RSat::ESetUpIdleModeTextTypeNotSet;
       
   194 			setUpIdleModeTextV1.iText.Zero();
       
   195 
       
   196 			CTlv textString;
       
   197 			returnValue = berTlv.TlvByTagValue( &textString, 
       
   198 			    KTlvTextStringTag );
       
   199 
       
   200 			// If the returnValue is KErrNone
       
   201 			if ( KErrNone == returnValue )
       
   202 				{
       
   203 				if ( textString.GetLength() )
       
   204 					{
       
   205 					// Convert and set text
       
   206 					TSatUtility::SetText( textString, 
       
   207 					    setUpIdleModeTextV1.iText );
       
   208 					//set type
       
   209 					setUpIdleModeTextV1.iType = RSat::EUpdateIdleModeText;
       
   210 					}
       
   211 				else
       
   212 					{
       
   213 					//set type
       
   214 					setUpIdleModeTextV1.iType = 
       
   215 					    RSat::ERemoveExistingIdleModeText;
       
   216 					}
       
   217 				}
       
   218 
       
   219 			// Iconid (optional)
       
   220 			TSatUtility::FillIconStructure( berTlv, 
       
   221 				setUpIdleModeTextV1.iIconId );
       
   222 			
       
   223 			if( (KErrNone != returnValue) ||
       
   224 				( ( RSat::ERemoveExistingIdleModeText == setUpIdleModeTextV1.iType) && 
       
   225 				  ( RSat::ENotSelfExplanatory==setUpIdleModeTextV1.iIconId.iQualifier)) )
       
   226 				{
       
   227 				TFLOGSTRING("CSAT: CSatNotifySetUpIdleModeText::\
       
   228 								    CompleteNotifyL, Invalid Data");
       
   229 				additionalInfo.Zero();
       
   230                 additionalInfo.Append( KNoCause );
       
   231 				CreateTerminalRespL( pCmdNumber, RSat::KCmdDataNotUnderstood, 
       
   232 					additionalInfo );                         				
       
   233 				ret = KErrCorrupt;
       
   234 				}					    
       
   235 			
       
   236 
       
   237 			} // End of if (KErrNone == aErrorCode)
       
   238         else
       
   239         	{
       
   240         	ret = aErrorCode;
       
   241         	}
       
   242 
       
   243         iNotificationsTsy->iSatTsy->ReqCompleted( reqHandle, ret );
       
   244         } // End of if ( reqHandle != CSatTsy::ESatReqHandleUnknown )
       
   245     else 
       
   246         {
       
   247         TFLOGSTRING("CSAT: CSatNotifySetUpIdleModeText::CompleteNotifyL,\
       
   248             Request not ongoing");
       
   249         // Request not on, returning response immediately
       
   250 		additionalInfo.Zero();
       
   251         additionalInfo.Append( KNoCause );
       
   252 		CreateTerminalRespL(
       
   253 			pCmdNumber, RSat::KMeUnableToProcessCmd,       
       
   254 			additionalInfo );					
       
   255 		}
       
   256 		
       
   257     return ret;
       
   258 	}
       
   259 
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CSatNotifySetUpIdleModeText::TerminalResponseL
       
   263 // Called by ETel server, passes terminal response to DOS
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 TInt CSatNotifySetUpIdleModeText::TerminalResponseL
       
   267         ( 
       
   268         TDes8* aRsp 
       
   269         )
       
   270     {
       
   271     TFLOGSTRING("CSAT: CSatNotifySetUpIdleModeText::TerminalResponseL");
       
   272 
       
   273 	TInt   ret( KErrNone );
       
   274     TBuf<1> additionalInfo;
       
   275     additionalInfo.Zero();
       
   276     RSat::TSetUpIdleModeTextRspV1Pckg* aRspPckg = 
       
   277             reinterpret_cast<RSat::TSetUpIdleModeTextRspV1Pckg*>( aRsp );
       
   278     RSat::TSetUpIdleModeTextRspV1& rspV1 = ( *aRspPckg ) ();
       
   279     // Get Proactive command number
       
   280     TUint8 pCmdNumber( rspV1.PCmdNumber() );
       
   281 
       
   282     // Check that general result value is valid
       
   283     if ( ( RSat::KSuccess != rspV1.iGeneralResult ) && 
       
   284          ( RSat::KPSessionTerminatedByUser  != rspV1.iGeneralResult ) && 
       
   285          ( RSat::KBackwardModeRequestedByUser != rspV1.iGeneralResult ) && 
       
   286          ( RSat::KNoResponseFromUser != rspV1.iGeneralResult ) && 
       
   287          ( RSat::KMeUnableToProcessCmd != rspV1.iGeneralResult ) && 
       
   288          ( RSat::KCmdBeyondMeCapabilities != rspV1.iGeneralResult ) && 
       
   289          ( RSat::KCmdDataNotUnderstood != rspV1.iGeneralResult ) &&
       
   290          ( RSat::KSuccessRequestedIconNotDisplayed != rspV1.iGeneralResult ) )
       
   291         {
       
   292         TFLOGSTRING("CSAT: CSatNotifySetUpIdleModeText::TerminalResponseL,\
       
   293             Invalid General Result");
       
   294         // Invalid general result
       
   295         ret = KErrCorrupt;
       
   296         }
       
   297 
       
   298     // If there is Me (Mobile Equipment) error, additional info is needed
       
   299     if ( ( RSat::KMeProblem == rspV1.iInfoType ) )
       
   300         {
       
   301         // Check the length of additional info
       
   302         if ( 0 != rspV1.iAdditionalInfo.Length()  )
       
   303             {
       
   304             additionalInfo.Append( ( TUint8 ) rspV1.iAdditionalInfo[0] );
       
   305 			}
       
   306         else
       
   307             {
       
   308             TFLOGSTRING("CSAT: CSatNotifySetUpIdleModeText::TerminalResponseL,\
       
   309                 Invalid Additional Info");
       
   310             // Invalid additional info field
       
   311             ret = KErrCorrupt;
       
   312             }
       
   313         }
       
   314         
       
   315     CreateTerminalRespL( pCmdNumber, static_cast<TUint8>( 
       
   316         rspV1.iGeneralResult ), additionalInfo );                            
       
   317 
       
   318 	return ret;
       
   319     }
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 // CSatNotifySetUpIdleModeText::CreateTerminalRespL
       
   323 // Constructs SetUpIdleModeText specific part of terminal response and calls 
       
   324 // DOS to send the actual message.
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 TInt CSatNotifySetUpIdleModeText::CreateTerminalRespL
       
   328         ( 
       
   329         TUint8 aPCmdNumber,       
       
   330         TUint8 aGeneralResult,      
       
   331         TDesC16& aAdditionalInfo			
       
   332 		)
       
   333     {
       
   334 	TFLOGSTRING("CSAT: CSatNotifySetUpIdleModeText::CreateTerminalRespL");
       
   335 	TTlv tlvSpecificData;
       
   336     // Create General Result TLV here
       
   337     tlvSpecificData.AddTag( KTlvResultTag );
       
   338     // General result
       
   339     tlvSpecificData.AddByte( aGeneralResult );
       
   340 
       
   341     if ( !( iNotificationsTsy->CommandPerformedSuccessfully( aGeneralResult ) ) )
       
   342         {
       
   343         switch ( aGeneralResult )
       
   344             {
       
   345             // Cases in which additional info is not required
       
   346             case RSat::KPSessionTerminatedByUser:
       
   347             case RSat::KBackwardModeRequestedByUser:
       
   348             case RSat::KNoResponseFromUser:
       
   349             case RSat::KErrorRequiredValuesMissing:
       
   350             case RSat::KHelpRequestedByUser:
       
   351             case RSat::KCmdDataNotUnderstood:
       
   352                 {
       
   353                 break;
       
   354                 }
       
   355             default:
       
   356                 {
       
   357                 if ( aAdditionalInfo.Length() )
       
   358                     {
       
   359                     tlvSpecificData.AddByte( ( TUint8 ) aAdditionalInfo[0] );
       
   360                     }
       
   361 				break;
       
   362                 }
       
   363             }
       
   364         }
       
   365 
       
   366     // Prepare data
       
   367     iNotificationsTsy->iTerminalRespData.iPCmdNumber = aPCmdNumber;
       
   368     TPtrC8 data = tlvSpecificData.GetDataWithoutTopLevelTag();
       
   369 
       
   370     // Pack data
       
   371     CSatDataPackage dataPackage;
       
   372 	dataPackage.PackData( &iNotificationsTsy->iTerminalRespData, &data );
       
   373 
       
   374     // Forward request to the DOS
       
   375     return iNotificationsTsy->iSatTsy->MessageManager()->HandleRequestL( 
       
   376 		ESatTerminalRsp, &dataPackage );
       
   377     }
       
   378     
       
   379 // End of file
       
   380