atext/server/src/atextsession.cpp
changeset 0 29b1cd4cb562
child 16 9f17f914e828
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <badesca.h>
       
    20 #include <atextpluginbase.h>
       
    21 #include <atext.h>
       
    22 #include "atextsrv.h"
       
    23 #include "atextclientsrv.h"
       
    24 #include "atextsession.h"
       
    25 #include "utils.h"
       
    26 #include "debug.h"
       
    27 
       
    28 // ================= MEMBER FUNCTIONS =======================
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // Two-phased constructor.
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 CATExtSession* CATExtSession::NewL( CATExtSrv& aServer,
       
    35                                     const TVersion& aVersion )
       
    36     {
       
    37     return new (ELeave) CATExtSession( aServer, aVersion );
       
    38     }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // Destructor.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CATExtSession::~CATExtSession()
       
    45     {
       
    46     TRACE_FUNC_ENTRY
       
    47     Destruct( EFalse );
       
    48     TRACE_FUNC_EXIT
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // Handles the servicing of client requests passed to the server
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 void CATExtSession::ServiceL( const RMessage2& aMessage )
       
    56     {
       
    57     TRACE_FUNC_ENTRY
       
    58     if ( iVersion.iMajor==KServerMajorVersionNumber &&
       
    59          iVersion.iMinor==KServerMinorVersionNumber &&
       
    60          iVersion.iBuild==KServerBuildVersionNumber )
       
    61         {
       
    62         DoServiceL( aMessage );
       
    63         }
       
    64     else
       
    65         {
       
    66         aMessage.Complete( KErrNotSupported );
       
    67         }
       
    68     TRACE_FUNC_EXIT
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // Handles the servicing of client requests passed to the server
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CATExtSession::DoServiceL( const RMessage2& aMessage )
       
    76     {
       
    77     TRACE_FUNC_ENTRY
       
    78     switch ( aMessage.Function() )
       
    79         {
       
    80         case EATExtSetExtensionInterface:
       
    81             {
       
    82             TRAPD( retTrap, IpcSetInterfaceL(aMessage) );
       
    83             if ( retTrap != KErrNone )
       
    84                 {
       
    85                 aMessage.Complete( retTrap );
       
    86                 }
       
    87             else if ( !iMetadata->SupportExists() )
       
    88                 {
       
    89                 aMessage.Complete( KErrNotFound );
       
    90                 }
       
    91             else
       
    92                 {
       
    93                 aMessage.Complete( KErrNone );
       
    94                 }
       
    95             break;
       
    96             }
       
    97         case EATExtSynchronousClose:
       
    98             {
       
    99             IpcSynchronousClose( aMessage );
       
   100             }
       
   101             break;
       
   102         case EATExtHandleCommand:
       
   103             {
       
   104             IpcHandleCommand( aMessage );
       
   105             break;
       
   106             }
       
   107         case EATExtCancelHandleCommand:
       
   108             {
       
   109             IpcCancelHandleCommand( aMessage );
       
   110             break;
       
   111             }
       
   112         case EATExtGetNextPartOfReply:
       
   113             {
       
   114             IpcGetNextPartOfReply( aMessage );
       
   115             break;
       
   116             }
       
   117         case EATExtNumberOfPlugins:
       
   118             {
       
   119             IpcNumberOfPlugins( aMessage );
       
   120             }
       
   121             break;
       
   122         case EATExtReceiveUnsolicitedResult:
       
   123             {
       
   124             IpcReceiveUnsolicitedResult( aMessage );
       
   125             break;
       
   126             }
       
   127         case EATExtCancelReceiveUnsolicitedResult:
       
   128             {
       
   129             IpcCancelReceiveUrc( aMessage );
       
   130             break;
       
   131             }
       
   132         case EATExtMarkUrcHandlingOwnership:
       
   133             {
       
   134             IpcMarkUrcHandlingOwnership( aMessage );
       
   135             break;
       
   136             }
       
   137         case EATExtReceiveEcomPluginChange:
       
   138             {
       
   139             IpcReceiveEcomPluginChange( aMessage );
       
   140             }
       
   141             break;
       
   142         case EATExtCancelReceiveEcomPluginChange:
       
   143             {
       
   144             IpcCancelReceiveEcomPluginChange( aMessage );
       
   145             }
       
   146             break;
       
   147         case EATExtReportQuietModeChange:
       
   148             {
       
   149             IpcReportQuietModeChange( aMessage );
       
   150             }
       
   151             break;
       
   152         case EATExtReportVerboseModeChange:
       
   153             {
       
   154             IpcReportVerboseModeChange( aMessage );
       
   155             }
       
   156             break;
       
   157         case EATExtReportCharacterChange:
       
   158             {
       
   159             IpcReportCharacterChange( aMessage );
       
   160             }
       
   161             break;
       
   162         case EATExtReportListenerUpdateReady:
       
   163             {
       
   164             IpcReportListenerUpdateReady( aMessage );
       
   165             }
       
   166             break;
       
   167         case EATExtBroadcastNvramStatusChange:
       
   168             {
       
   169             IpcBroadcastNvramStatusChange( aMessage );
       
   170             }
       
   171             break;
       
   172         case EATExtReportExternalHandleCommandError:
       
   173             {
       
   174             IpcReportExternalHandleCommandError( aMessage );
       
   175             }
       
   176             break;
       
   177         case EATExtReportHandleCommandAbort:
       
   178             {
       
   179             IpcReportHandleCommandAbort( aMessage );
       
   180             }
       
   181             break;
       
   182         case EATExtGetNextSpecialCommand:
       
   183             {
       
   184             IpcGetNextSpecialCommand( aMessage );
       
   185             }
       
   186             break;
       
   187         default:
       
   188             {
       
   189             aMessage.Complete( KErrNotSupported );
       
   190             break;
       
   191             }
       
   192         }
       
   193     TRACE_FUNC_EXIT
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // CATExtSession::CATExtSession
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 CATExtSession::CATExtSession( CATExtSrv& aServer, const TVersion& aVersion ) :
       
   201     iServer( aServer ),
       
   202     iListener( NULL ),
       
   203     iMetadata( NULL ),
       
   204     iVersion( aVersion )
       
   205     {
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // Handles the servicing of setting up interface
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 void CATExtSession::IpcSetInterfaceL( const RMessage2& aMessage )
       
   213     {
       
   214     TRACE_FUNC_ENTRY
       
   215     if ( iMetadata || iListener )
       
   216         {
       
   217         TRACE_FUNC_EXIT
       
   218         User::Leave( KErrGeneral );
       
   219         }
       
   220     REComSession& ecomSession = REComSession::OpenL();
       
   221     CleanupClosePushL( ecomSession );
       
   222     TPckgBuf<TUid> ifUidPckgBuf;
       
   223     TInt retTemp = ReadStructFromMessage( ifUidPckgBuf,
       
   224                                           EATExtConnectParamUid,
       
   225                                           aMessage );
       
   226     if ( retTemp != KErrNone )
       
   227         {
       
   228         TRACE_FUNC_EXIT
       
   229         User::Leave( retTemp );
       
   230         }
       
   231     RBuf8 connectionName;
       
   232     CleanupClosePushL( connectionName );
       
   233     retTemp = ReadStringFromMessage( connectionName,
       
   234                                      EATExtConnectParamName,
       
   235                                      aMessage );
       
   236     if ( retTemp != KErrNone )
       
   237         {
       
   238         TRACE_FUNC_EXIT
       
   239         User::Leave( retTemp );
       
   240         }
       
   241     // Create listener
       
   242     CATExtListen* listener = CATExtListen::NewLC( ecomSession, this );
       
   243     listener->AddInterfaceUid( ifUidPckgBuf() );
       
   244     // Create metadata. Pass iListener to add the UIDs
       
   245     CATExtMetadata* metadata = CATExtMetadata::NewLC( ecomSession,
       
   246                                                       listener,
       
   247                                                       *this );
       
   248     metadata->CreateImplementationMetadataL( ifUidPckgBuf(), connectionName );
       
   249     listener->IssueRequest();
       
   250     CleanupStack::Pop( metadata );
       
   251     CleanupStack::Pop( listener );
       
   252     CleanupStack::PopAndDestroy( &connectionName );
       
   253     CleanupStack::Pop( &ecomSession );
       
   254     iEComSession = ecomSession;
       
   255     iListener = listener;
       
   256     iMetadata = metadata;
       
   257     TRACE_FUNC_EXIT
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // Synchronously closes the session
       
   262 // Optional: client can do either Close() or SynchronousClose()
       
   263 // ---------------------------------------------------------------------------
       
   264 //
       
   265 TInt CATExtSession::IpcSynchronousClose( const RMessage2& aMessage )
       
   266     {
       
   267     TRACE_FUNC_ENTRY
       
   268     Destruct( ETrue );
       
   269     aMessage.Complete( KErrNone );
       
   270     TRACE_FUNC_EXIT
       
   271     return KErrNone;
       
   272     }
       
   273 
       
   274 // ---------------------------------------------------------------------------
       
   275 // Handles the servicing of AT commands
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 TInt CATExtSession::IpcHandleCommand( const RMessage2& aMessage )
       
   279     {
       
   280     TRACE_FUNC_ENTRY
       
   281     if ( !iMetadata )
       
   282         {
       
   283         aMessage.Complete( KErrGeneral );
       
   284         TRACE_FUNC_EXIT
       
   285         return KErrGeneral;
       
   286         }
       
   287     if ( aMessage.GetDesMaxLength(EATExtHandleCmdParamReply) !=
       
   288          KDefaultCmdBufLength )
       
   289         {
       
   290         aMessage.Complete( KErrBadDescriptor );
       
   291         TRACE_FUNC_EXIT
       
   292         return KErrBadDescriptor;
       
   293         }
       
   294     TATExtCompletionInfo complInfo;
       
   295     complInfo.iProcessed = EFalse;
       
   296     complInfo.iReplyExpected = EFalse;
       
   297     TInt retTemp = iMetadata->HandleCommand( aMessage, complInfo );
       
   298     if ( retTemp != KErrNone )
       
   299         {
       
   300         TRACE_INFO(( _L8("Command handled with failure %d"), retTemp ));
       
   301         iMetadata->CompleteCommandMessage( NULL,
       
   302                                            retTemp,
       
   303                                            EFalse,               // no error reply
       
   304                                            EReplyTypeUndefined,  // general error condition
       
   305                                            EFalse );             // no multipart
       
   306         TRACE_FUNC_EXIT
       
   307         return retTemp;
       
   308         }
       
   309     // Next check the case without support: in this case a reply
       
   310     // can't be expected but return the "ERROR" anyway if needed.
       
   311     if ( !complInfo.iProcessed )
       
   312         {
       
   313         // Return "ERROR".
       
   314         TRACE_INFO(( _L8("Command handled without support: return \"ERROR\"") ));
       
   315         iMetadata->CompleteCommandMessage( NULL,
       
   316                                            KErrNone,
       
   317                                            ETrue,            // error reply
       
   318                                            EReplyTypeError,  // error type
       
   319                                            EFalse );         // no multipart
       
   320         TRACE_FUNC_EXIT
       
   321         return retTemp;
       
   322         }
       
   323     // Third, check a case where there is support but reply is not
       
   324     // expected. In this case "" must be returned to complete processing.
       
   325     if ( !complInfo.iReplyExpected )
       
   326         {
       
   327         // Return ""
       
   328         TRACE_INFO(( _L8("Command handled with support but no reply: return \"\"") ));
       
   329         iMetadata->CompleteCommandMessage( NULL,
       
   330                                            KErrNone,
       
   331                                            EFalse,           // no error reply
       
   332                                            EReplyTypeOther,  // reply type from plugin
       
   333                                            EFalse );         // no multipart
       
   334         TRACE_FUNC_EXIT
       
   335         return retTemp;
       
   336         }
       
   337     // The rest are for known command with reply. This case is handled in
       
   338     // HandleCommand().
       
   339     TRACE_INFO(( _L8("Command handled: wait for asynchronous reply or do nothing") ));
       
   340     TRACE_FUNC_EXIT
       
   341     return KErrNone;
       
   342     }
       
   343 
       
   344 // ---------------------------------------------------------------------------
       
   345 // Handles the servicing of pending AT command cancel
       
   346 // ---------------------------------------------------------------------------
       
   347 //
       
   348 TInt CATExtSession::IpcCancelHandleCommand( const RMessage2& aMessage )
       
   349     {
       
   350     TRACE_FUNC_ENTRY
       
   351     if ( !iMetadata )
       
   352         {
       
   353         aMessage.Complete( KErrGeneral );
       
   354         TRACE_FUNC_EXIT
       
   355         return KErrGeneral;
       
   356         }
       
   357     TInt retVal = iMetadata->CancelHandleCommand();
       
   358     aMessage.Complete( retVal );
       
   359     TRACE_FUNC_EXIT
       
   360     return retVal;
       
   361     }
       
   362 
       
   363 // ---------------------------------------------------------------------------
       
   364 // Handles the servicing of getting the next part of a reply for
       
   365 // IpcHandleCommand().
       
   366 // ---------------------------------------------------------------------------
       
   367 //
       
   368 TInt CATExtSession::IpcGetNextPartOfReply( const RMessage2& aMessage )
       
   369     {
       
   370     TRACE_FUNC_ENTRY
       
   371     if ( !iMetadata )
       
   372         {
       
   373         aMessage.Complete( KErrGeneral );
       
   374         TRACE_FUNC_EXIT
       
   375         return KErrGeneral;
       
   376         }
       
   377     TInt retTemp = iMetadata->GetNextPartOfReply( aMessage );
       
   378     if ( retTemp != KErrNone )
       
   379         {
       
   380         aMessage.Complete( retTemp );
       
   381         TRACE_FUNC_EXIT
       
   382         return retTemp;
       
   383         }
       
   384     // Note: Completed in metadata if successfull
       
   385     TRACE_FUNC_EXIT
       
   386     return KErrNone;
       
   387     }
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // Handles the servicing of number of plugins. This information is needed to
       
   391 // instantiate one or more listeners by the user of the client.
       
   392 // ---------------------------------------------------------------------------
       
   393 //
       
   394 TInt CATExtSession::IpcNumberOfPlugins( const RMessage2& aMessage )
       
   395     {
       
   396     TRACE_FUNC_ENTRY
       
   397     if ( !iMetadata )
       
   398         {
       
   399         aMessage.Complete( KErrGeneral );
       
   400         TRACE_FUNC_EXIT
       
   401         return KErrGeneral;
       
   402         }
       
   403     TInt retVal = iMetadata->NumberOfPlugins();
       
   404     aMessage.Complete( retVal );
       
   405     TRACE_FUNC_EXIT
       
   406     return retVal;
       
   407     }
       
   408 
       
   409 // ---------------------------------------------------------------------------
       
   410 // Handles the servicing of receiving unsolicited result codes. Note that
       
   411 // IpcMarkUrcHandlingOwnership() must be called immediately after this in
       
   412 // order for the message to receive their destination.
       
   413 // ---------------------------------------------------------------------------
       
   414 //
       
   415 TInt CATExtSession::IpcReceiveUnsolicitedResult( const RMessage2& aMessage )
       
   416     {
       
   417     TRACE_FUNC_ENTRY
       
   418     if ( !iMetadata )
       
   419         {
       
   420         aMessage.Complete( KErrGeneral );
       
   421         TRACE_FUNC_EXIT
       
   422         return KErrGeneral;
       
   423         }
       
   424     if ( aMessage.GetDesMaxLength(EATExtReceiveUrcCmdParamBuf) !=
       
   425          KDefaultUrcBufLength )
       
   426         {
       
   427         aMessage.Complete( KErrBadDescriptor );
       
   428         TRACE_FUNC_EXIT
       
   429         return KErrBadDescriptor;
       
   430         }
       
   431     TPckgBuf<TUid> pluginUidPckgBuf;
       
   432     TInt retTemp = ReadStructFromMessage( pluginUidPckgBuf,
       
   433                                           EATExtReceiveUrcCmdParamUid,
       
   434                                           aMessage );
       
   435     if ( retTemp != KErrNone )
       
   436         {
       
   437         aMessage.Complete( retTemp );
       
   438         TRACE_FUNC_EXIT
       
   439         return retTemp;
       
   440         }
       
   441     TRAPD( retTrap, iMetadata->StartUrcReceivingL(aMessage,pluginUidPckgBuf()) );
       
   442     if ( retTrap != KErrNone )
       
   443         {
       
   444         aMessage.Complete( retTrap );
       
   445         TRACE_FUNC_EXIT
       
   446         return retTrap;
       
   447         }
       
   448     TRACE_FUNC_EXIT
       
   449     return KErrNone;
       
   450     }
       
   451 
       
   452 // ---------------------------------------------------------------------------
       
   453 // Handles the servicing of pending receiving unsolicited result code cancel
       
   454 // ---------------------------------------------------------------------------
       
   455 //
       
   456 TInt CATExtSession::IpcCancelReceiveUrc( const RMessage2& aMessage )
       
   457     {
       
   458     TRACE_FUNC_ENTRY
       
   459     if ( !iMetadata )
       
   460         {
       
   461         aMessage.Complete( KErrGeneral );
       
   462         TRACE_FUNC_EXIT
       
   463         return KErrGeneral;
       
   464         }
       
   465     TPckgBuf<TUid> pluginUidPckgBuf;
       
   466     TInt retTemp = ReadStructFromMessage( pluginUidPckgBuf,
       
   467                                           EATExtCancelReceiveUrcCmdParamUid,
       
   468                                           aMessage );
       
   469     if ( retTemp != KErrNone )
       
   470         {
       
   471         aMessage.Complete( retTemp );
       
   472         TRACE_FUNC_EXIT
       
   473         return retTemp;
       
   474         }
       
   475     TInt retVal = iMetadata->CancelUrcReceiving( pluginUidPckgBuf() );
       
   476     aMessage.Complete( retVal );
       
   477     TRACE_FUNC_EXIT
       
   478     return retVal;
       
   479     }
       
   480 
       
   481 // ---------------------------------------------------------------------------
       
   482 // Handles the servicing of marking URC handling ownership. Call to this
       
   483 // function must be done immediately after the call to
       
   484 // IpcReceiveUnsolicitedResult().
       
   485 // ---------------------------------------------------------------------------
       
   486 //
       
   487 TInt CATExtSession::IpcMarkUrcHandlingOwnership( const RMessage2& aMessage )
       
   488     {
       
   489     TRACE_FUNC_ENTRY
       
   490     if ( !iMetadata )
       
   491         {
       
   492         aMessage.Complete( KErrGeneral );
       
   493         TRACE_FUNC_EXIT
       
   494         return KErrGeneral;
       
   495         }
       
   496     TInt retVal = iMetadata->MarkUrcHandlingOwnership( aMessage );
       
   497     aMessage.Complete( retVal );
       
   498     TRACE_FUNC_EXIT
       
   499     return retVal;
       
   500     }
       
   501 
       
   502 // ---------------------------------------------------------------------------
       
   503 // Handles the servicing of ECOM plugin change notifications
       
   504 // ---------------------------------------------------------------------------
       
   505 //
       
   506 TInt CATExtSession::IpcReceiveEcomPluginChange( const RMessage2& aMessage )
       
   507     {
       
   508     TRACE_FUNC_ENTRY
       
   509     if ( !iMetadata )
       
   510         {
       
   511         aMessage.Complete( KErrGeneral );
       
   512         TRACE_FUNC_EXIT
       
   513         return KErrGeneral;
       
   514         }
       
   515     if ( iEcomStatusMessage.Handle() )
       
   516         {
       
   517         aMessage.Complete( KErrBadHandle );
       
   518         TRACE_FUNC_EXIT
       
   519         return KErrBadHandle;
       
   520         }
       
   521     iEcomStatusMessage = aMessage;
       
   522     TRACE_FUNC_EXIT
       
   523     return KErrNone;
       
   524     }
       
   525 
       
   526 // ---------------------------------------------------------------------------
       
   527 // Handles the servicing of pending ECOM plugin change notification cancel
       
   528 // ---------------------------------------------------------------------------
       
   529 //
       
   530 TInt CATExtSession::IpcCancelReceiveEcomPluginChange(
       
   531     const RMessage2& aMessage )
       
   532     {
       
   533     TRACE_FUNC_ENTRY
       
   534     if ( !iMetadata )
       
   535         {
       
   536         aMessage.Complete( KErrGeneral );
       
   537         TRACE_FUNC_EXIT
       
   538         return KErrGeneral;
       
   539         }
       
   540     if ( !iEcomStatusMessage.Handle() )
       
   541         {
       
   542         aMessage.Complete( KErrBadHandle );
       
   543         TRACE_FUNC_EXIT
       
   544         return KErrBadHandle;
       
   545         }
       
   546     iEcomStatusMessage.Complete( KErrCancel );
       
   547     aMessage.Complete( KErrNone );
       
   548     TRACE_FUNC_EXIT
       
   549     return KErrNone;
       
   550     }
       
   551 
       
   552 // ---------------------------------------------------------------------------
       
   553 // Handles the servicing of quiet mode change reporting. When quiet mode is on
       
   554 // the behavior is the same as with AT command "ATQ1: Result code
       
   555 // suppression". When quiet mode is on then verbose mode setting has no
       
   556 // effect.
       
   557 // ---------------------------------------------------------------------------
       
   558 //
       
   559 TInt CATExtSession::IpcReportQuietModeChange( const RMessage2& aMessage )
       
   560     {
       
   561     TRACE_FUNC_ENTRY
       
   562     if ( !iMetadata )
       
   563         {
       
   564         aMessage.Complete( KErrGeneral );
       
   565         TRACE_FUNC_EXIT
       
   566         return KErrGeneral;
       
   567         }
       
   568     TPckgBuf<TBool> quietModePckgBuf;
       
   569     TInt retTemp = ReadStructFromMessage( quietModePckgBuf,
       
   570                                           EATExtReportQuietModeChangeParamMode,
       
   571                                           aMessage );
       
   572     if ( retTemp != KErrNone )
       
   573         {
       
   574         aMessage.Complete( retTemp );
       
   575         TRACE_FUNC_EXIT
       
   576         return retTemp;
       
   577         }
       
   578     iMetadata->SetQuietMode( quietModePckgBuf() );
       
   579     aMessage.Complete( KErrNone );
       
   580     TRACE_FUNC_EXIT
       
   581     return KErrNone;
       
   582     }
       
   583 
       
   584 // ---------------------------------------------------------------------------
       
   585 // Handles the servicing of verbose mode change reporting. When verbose mode
       
   586 // is on the behavior is the same as with AT command "ATV1: DCE Response
       
   587 // format". If quiet mode is on then this setting has no effect.
       
   588 // ---------------------------------------------------------------------------
       
   589 //
       
   590 TInt CATExtSession::IpcReportVerboseModeChange( const RMessage2& aMessage )
       
   591     {
       
   592     TRACE_FUNC_ENTRY
       
   593     if ( !iMetadata )
       
   594         {
       
   595         aMessage.Complete( KErrGeneral );
       
   596         TRACE_FUNC_EXIT
       
   597         return KErrGeneral;
       
   598         }
       
   599     TPckgBuf<TBool> verboseModePckgBuf;
       
   600     TInt retTemp = ReadStructFromMessage( verboseModePckgBuf,
       
   601                                           EATExtReportVerboseModeChangeParamMode,
       
   602                                           aMessage );
       
   603     if ( retTemp != KErrNone )
       
   604         {
       
   605         aMessage.Complete( retTemp );
       
   606         TRACE_FUNC_EXIT
       
   607         return retTemp;
       
   608         }
       
   609     iMetadata->SetVerboseMode( verboseModePckgBuf() );
       
   610     aMessage.Complete( KErrNone );
       
   611     TRACE_FUNC_EXIT
       
   612     return KErrNone;
       
   613     }
       
   614 
       
   615 // ---------------------------------------------------------------------------
       
   616 // Handles the servicing of character change reporting. The change to carriage
       
   617 // return, line feed and backspace characters is reported to
       
   618 // CATExtPluginBase's protected data so that the it can easily be used by the
       
   619 // plugin implementation.
       
   620 // ---------------------------------------------------------------------------
       
   621 //
       
   622 TInt CATExtSession::IpcReportCharacterChange( const RMessage2& aMessage )
       
   623     {
       
   624     TRACE_FUNC_ENTRY
       
   625     if ( !iMetadata )
       
   626         {
       
   627         aMessage.Complete( KErrGeneral );
       
   628         TRACE_FUNC_EXIT
       
   629         return KErrGeneral;
       
   630         }
       
   631     TPckgBuf<TATExtensionCharType> charTypePckgBuf;
       
   632     TInt retTemp = ReadStructFromMessage( charTypePckgBuf,
       
   633                                           EATExtReportCharacterChangeParamType,
       
   634                                           aMessage );
       
   635     if ( retTemp != KErrNone )
       
   636         {
       
   637         aMessage.Complete( retTemp );
       
   638         TRACE_FUNC_EXIT
       
   639         return retTemp;
       
   640         }
       
   641     TPckgBuf<TInt8> charPckgBuf;
       
   642     retTemp = ReadStructFromMessage( charPckgBuf,
       
   643                                      EATExtReportCharacterChangeParamChar,
       
   644                                      aMessage );
       
   645     if ( retTemp != KErrNone )
       
   646         {
       
   647         aMessage.Complete( retTemp );
       
   648         TRACE_FUNC_EXIT
       
   649         return retTemp;
       
   650         }
       
   651     TInt retVal = iMetadata->SetCharacterValue( charTypePckgBuf(),
       
   652                                                 charPckgBuf() );
       
   653     aMessage.Complete( retVal );
       
   654     TRACE_FUNC_EXIT
       
   655     return retVal;
       
   656     }
       
   657 
       
   658 // ---------------------------------------------------------------------------
       
   659 // Handles the servicing of reporting listener update readiness. Client side
       
   660 // listener has to use this after it has updates its own internal states after
       
   661 // ECOM plugin change notification.
       
   662 // ---------------------------------------------------------------------------
       
   663 //
       
   664 TInt CATExtSession::IpcReportListenerUpdateReady( const RMessage2& aMessage )
       
   665     {
       
   666     TRACE_FUNC_ENTRY
       
   667     if ( !iMetadata )
       
   668         {
       
   669         aMessage.Complete( KErrGeneral );
       
   670         TRACE_FUNC_EXIT
       
   671         return KErrGeneral;
       
   672         }
       
   673     TPckgBuf<TUid> pluginUidPckgBuf;
       
   674     TInt retTemp = ReadStructFromMessage( pluginUidPckgBuf,
       
   675                                           EATExtReportListenerUpdateParamUid,
       
   676                                           aMessage );
       
   677     if ( retTemp != KErrNone )
       
   678         {
       
   679         aMessage.Complete( retTemp );
       
   680         TRACE_FUNC_EXIT
       
   681         return retTemp;
       
   682         }
       
   683     TPckgBuf<TATExtensionEcomType> updateTypePckgBuf;
       
   684     retTemp = ReadStructFromMessage( updateTypePckgBuf,
       
   685                                      EATExtReportListenerUpdateParamType,
       
   686                                      aMessage );
       
   687     if ( retTemp != KErrNone )
       
   688         {
       
   689         aMessage.Complete( retTemp );
       
   690         TRACE_FUNC_EXIT
       
   691         return retTemp;
       
   692         }
       
   693     TInt retVal = KErrNone;
       
   694     switch ( updateTypePckgBuf() )
       
   695         {
       
   696         case EEcomTypeUninstall:
       
   697             // 3. When client notifies of removal, remove the locked entry from metadata.
       
   698             // See also NotifyPluginUninstallation()
       
   699             retVal = iMetadata->RemoveImplementation( pluginUidPckgBuf() );
       
   700             break;
       
   701         case EEcomTypeInstall:
       
   702             // 4. When client notifies installation, remove the lock from metadata.
       
   703             // See also NotifyPluginInstallation()
       
   704             retVal = iMetadata->UnlockPluginAccess( pluginUidPckgBuf() );
       
   705             break;
       
   706         default:
       
   707             retVal = KErrNotSupported;
       
   708             break;
       
   709         }
       
   710     aMessage.Complete( retVal );
       
   711     TRACE_FUNC_EXIT
       
   712     return retVal;
       
   713     }
       
   714 
       
   715 // ---------------------------------------------------------------------------
       
   716 // Handles the servicing of NVRAM status change broadcasting. The NVRAM status
       
   717 // change is broadcasted to all of the plugins.
       
   718 // ---------------------------------------------------------------------------
       
   719 //
       
   720 TInt CATExtSession::IpcBroadcastNvramStatusChange( const RMessage2& aMessage )
       
   721     {
       
   722     TRACE_FUNC_ENTRY
       
   723     if ( !iMetadata )
       
   724         {
       
   725         aMessage.Complete( KErrGeneral );
       
   726         TRACE_FUNC_EXIT
       
   727         return KErrGeneral;
       
   728         }
       
   729     RBuf8 nvramStatus;
       
   730     TInt retTemp = ReadStringFromMessage( nvramStatus,
       
   731                                           EATExtBroadcastNvramChangeParamNvram,
       
   732                                           aMessage );
       
   733     if ( retTemp != KErrNone )
       
   734         {
       
   735         aMessage.Complete( retTemp );
       
   736         nvramStatus.Close();
       
   737         TRACE_FUNC_EXIT
       
   738         return retTemp;
       
   739         }
       
   740     TInt retVal = iMetadata->BroadcastNvramStatusChange( nvramStatus );
       
   741     aMessage.Complete( retVal );
       
   742     nvramStatus.Close();
       
   743     TRACE_FUNC_EXIT
       
   744     return KErrNone;
       
   745     }
       
   746 
       
   747 // ---------------------------------------------------------------------------
       
   748 // Handles the servicing of reporting about external handle command error
       
   749 // condition.
       
   750 // This is for cases when for example DUN decided the reply contained an
       
   751 // error condition but the plugin is still handling the command internally.
       
   752 // Example: "AT+TEST;+TEST2" was given in command line; "AT+TEST" returns
       
   753 // non-EReplyTypeError condition and "AT+TEST2" returns EReplyTypeError.
       
   754 // As the plugin(s) returning the non-EReplyTypeError may still have some
       
   755 // ongoing operation then these plugins are notified about the external
       
   756 // EReplyTypeError in command line processing. It is to be noted that
       
   757 // HandleCommandCancel() is not sufficient to stop the processing as the
       
   758 // command handling has already finished.
       
   759 // ---------------------------------------------------------------------------
       
   760 //
       
   761 TInt CATExtSession::IpcReportExternalHandleCommandError(
       
   762     const RMessage2& aMessage )
       
   763     {
       
   764     TRACE_FUNC_ENTRY
       
   765     if ( !iMetadata )
       
   766         {
       
   767         aMessage.Complete( KErrGeneral );
       
   768         TRACE_FUNC_EXIT
       
   769         return KErrGeneral;
       
   770         }
       
   771     TInt retVal = iMetadata->ReportExternalHandleCommandError();
       
   772     aMessage.Complete( retVal );
       
   773     TRACE_FUNC_EXIT
       
   774     return KErrNone;
       
   775     }
       
   776 
       
   777 // ---------------------------------------------------------------------------
       
   778 // Handles the servicing of reporting about abort condition in command
       
   779 // handling.
       
   780 // This is for cases when for example DUN decided an abort condition was
       
   781 // received from DTE (ITU-T V.250 5.6.1). This API is for notifying the
       
   782 // plugin that abort was requested. However the plugin currently handling
       
   783 // the command may ignore the request if it doesn't support abort for the
       
   784 // command or it may return the changed condition with
       
   785 // HandleCommandCompleted()
       
   786 // ---------------------------------------------------------------------------
       
   787 //
       
   788 TInt CATExtSession::IpcReportHandleCommandAbort( const RMessage2& aMessage )
       
   789     {
       
   790     TRACE_FUNC_ENTRY
       
   791     if ( !iMetadata )
       
   792         {
       
   793         aMessage.Complete( KErrGeneral );
       
   794         TRACE_FUNC_EXIT
       
   795         return KErrGeneral;
       
   796         }
       
   797     TInt retVal = iMetadata->ReportHandleCommandAbort( aMessage );
       
   798     aMessage.Complete( retVal );
       
   799     TRACE_FUNC_EXIT
       
   800     return KErrNone;
       
   801     }
       
   802 
       
   803 // ---------------------------------------------------------------------------
       
   804 // Handles the servicing of getting the next special command RSS file entry.
       
   805 // These commands are commands with a matching start but with any ending
       
   806 // sequence. Command "ATD*99***1#" is one of these and the number of these
       
   807 // commands should be kept minimal.
       
   808 // ---------------------------------------------------------------------------
       
   809 //
       
   810 TInt CATExtSession::IpcGetNextSpecialCommand( const RMessage2& aMessage )
       
   811     {
       
   812     TRACE_FUNC_ENTRY
       
   813     if ( !iMetadata )
       
   814         {
       
   815         aMessage.Complete( KErrGeneral );
       
   816         TRACE_FUNC_EXIT
       
   817         return KErrGeneral;
       
   818         }
       
   819     TPckgBuf<TBool> firstSearchPckgBuf;
       
   820     TInt retTemp = ReadStructFromMessage( firstSearchPckgBuf,
       
   821                                           EATExtGetNextSpecialCmdParamFirst,
       
   822                                           aMessage );
       
   823     if ( retTemp != KErrNone )
       
   824         {
       
   825         aMessage.Complete( retTemp );
       
   826         TRACE_FUNC_EXIT
       
   827         return retTemp;
       
   828         }
       
   829     TInt retVal = iMetadata->GetNextSpecialCommand( aMessage,
       
   830                                                     firstSearchPckgBuf() );
       
   831     aMessage.Complete( retVal );
       
   832     TRACE_FUNC_EXIT
       
   833     return retVal;
       
   834     }
       
   835 
       
   836 // ---------------------------------------------------------------------------
       
   837 // Reads a string from a message
       
   838 // ---------------------------------------------------------------------------
       
   839 //
       
   840 TInt CATExtSession::ReadStringFromMessage( RBuf8& aBuffer,
       
   841                                            TInt aDataSlot,
       
   842                                            const RMessage2& aMessage )
       
   843     {
       
   844     TRACE_FUNC_ENTRY
       
   845     TInt retVal = KErrNone;
       
   846     TInt desLength = aMessage.GetDesLength( aDataSlot );
       
   847     if ( desLength <= 0 )
       
   848         {
       
   849         TRACE_FUNC_EXIT
       
   850         return KErrArgument;
       
   851         }
       
   852     retVal = aBuffer.Create( desLength );
       
   853     if ( retVal == KErrNone )
       
   854         {
       
   855         retVal = aMessage.Read( aDataSlot, aBuffer );
       
   856         TRACE_INFO(( _L("Read returned %d"), retVal ));
       
   857         }
       
   858     TRACE_FUNC_EXIT
       
   859     return retVal;
       
   860     }
       
   861 
       
   862 // ---------------------------------------------------------------------------
       
   863 // Reads a struct from a message
       
   864 // ---------------------------------------------------------------------------
       
   865 //
       
   866 TInt CATExtSession::ReadStructFromMessage( TDes8& aBuffer,
       
   867                                            TInt aDataSlot,
       
   868                                            const RMessage2& aMessage )
       
   869     {
       
   870     TRACE_FUNC_ENTRY
       
   871     TInt retVal = KErrNone;
       
   872     TInt desLength = aMessage.GetDesLength( aDataSlot );
       
   873     if ( desLength <= 0 )
       
   874         {
       
   875         TRACE_FUNC_EXIT
       
   876         return KErrArgument;
       
   877         }
       
   878     retVal = aMessage.Read( aDataSlot, aBuffer );
       
   879     TRACE_INFO(( _L("Read returned %d"), retVal ));
       
   880     TRACE_FUNC_EXIT
       
   881     return retVal;
       
   882     }
       
   883 
       
   884 // ---------------------------------------------------------------------------
       
   885 // Destructs objects/associations for the current session
       
   886 // ---------------------------------------------------------------------------
       
   887 //
       
   888 void CATExtSession::Destruct( TBool aSyncClose )
       
   889     {
       
   890     TRACE_FUNC_ENTRY
       
   891     if ( iEcomStatusMessage.Handle() )
       
   892         {
       
   893         iEcomStatusMessage.Complete( KErrServerTerminated );
       
   894         }
       
   895     delete iListener;
       
   896     iListener = NULL;
       
   897     delete iMetadata;
       
   898     iMetadata = NULL;
       
   899     iEComSession.Close();
       
   900     if ( !aSyncClose )
       
   901         {
       
   902         REComSession::FinalClose();
       
   903         iServer.ClientClosed( *this );
       
   904         }
       
   905     TRACE_FUNC_EXIT
       
   906     }
       
   907 
       
   908 // ---------------------------------------------------------------------------
       
   909 // From MATExtPluginObserver.
       
   910 // Called by extension plugins when there is an unsolicited result code
       
   911 // should be sent to destination.
       
   912 // ---------------------------------------------------------------------------
       
   913 //
       
   914 TInt CATExtSession::SendUnsolicitedResult( CATExtPluginBase* aPlugin,
       
   915                                            const TDesC8& aAT )
       
   916     {
       
   917     TRACE_FUNC_ENTRY
       
   918     if ( !iMetadata )
       
   919         {
       
   920         TRACE_FUNC_EXIT
       
   921         return KErrGeneral;
       
   922         }
       
   923     iMetadata->CompleteUrcMessage( aAT, aPlugin );
       
   924     TRACE_FUNC_EXIT
       
   925     return KErrNone;
       
   926     }
       
   927 
       
   928 // ---------------------------------------------------------------------------
       
   929 // From MATExtPluginObserver.
       
   930 // Called by Extension Plugins to inform ATEXT that a command handling has
       
   931 // been completed or rejected.
       
   932 // ---------------------------------------------------------------------------
       
   933 //
       
   934 TInt CATExtSession::HandleCommandCompleted( CATExtPluginBase* aPlugin,
       
   935                                             TInt aError,
       
   936                                             TATExtensionReplyType aReplyType )
       
   937     {
       
   938     TRACE_FUNC_ENTRY
       
   939     if ( !iMetadata )
       
   940         {
       
   941         TRACE_FUNC_EXIT
       
   942         return KErrGeneral;
       
   943         }
       
   944     TInt retVal = iMetadata->CompleteCommandMessage( aPlugin,
       
   945                                                      aError,
       
   946                                                      EFalse,      // no error reply
       
   947                                                      aReplyType,  // type of reply
       
   948                                                      ETrue );     // multipart
       
   949     TRACE_FUNC_EXIT
       
   950     return retVal;
       
   951     }
       
   952 
       
   953 // ---------------------------------------------------------------------------
       
   954 // From MATExtPluginObserver.
       
   955 // Called by concrete extension plugin to inform the array of supported
       
   956 // commands should be returned
       
   957 // ---------------------------------------------------------------------------
       
   958 //
       
   959 TInt CATExtSession::GetSupportedCommands( CATExtPluginBase* aPlugin,
       
   960                                           RPointerArray<HBufC8>& aCmds )
       
   961     {
       
   962     TRACE_FUNC_ENTRY
       
   963     if ( !iMetadata )
       
   964         {
       
   965         TRACE_FUNC_EXIT
       
   966         return KErrGeneral;
       
   967         }
       
   968     TInt retVal = iMetadata->GetSupportedCommands( aPlugin, aCmds );
       
   969     TRACE_FUNC_EXIT
       
   970     return retVal;
       
   971     }
       
   972 
       
   973 // ---------------------------------------------------------------------------
       
   974 // From MATExtPluginObserver.
       
   975 // Called by the destructor of CATExtPluginBase. A concrete service provider
       
   976 // implementation should not touch this.
       
   977 // ---------------------------------------------------------------------------
       
   978 //
       
   979 TInt CATExtSession::ATExtPluginClosed( CATExtPluginBase* aPlugin )
       
   980     {
       
   981     TRACE_FUNC_ENTRY
       
   982     if ( !iMetadata )
       
   983         {
       
   984         TRACE_FUNC_EXIT
       
   985         return KErrGeneral;
       
   986         }
       
   987     TInt retVal = iMetadata->RemoveImplementationInstance( aPlugin );
       
   988     // "delete this" used in plugin. Plugin must cancel asynchronous
       
   989     // operations in its destructor to complete iCommandMessage and
       
   990     // iUnsolicitedMessage
       
   991     TRACE_FUNC_EXIT
       
   992     return retVal;
       
   993     }
       
   994 
       
   995 // ---------------------------------------------------------------------------
       
   996 // From class MATExtListen.
       
   997 // Notifies about an installed plugin.
       
   998 // ---------------------------------------------------------------------------
       
   999 //
       
  1000 TInt CATExtSession::NotifyPluginInstallation(
       
  1001     TUid& /*aIfUid*/,
       
  1002     CImplementationInformation* aImplInfo )
       
  1003     {
       
  1004     TRACE_FUNC_ENTRY
       
  1005     if ( !iMetadata || !aImplInfo )
       
  1006         {
       
  1007         TRACE_FUNC_EXIT
       
  1008         return KErrGeneral;
       
  1009         }
       
  1010     // 1. Add the new UID to metadata.
       
  1011     TRAPD( retTrap, iMetadata->AddImplementationL( aImplInfo ) );
       
  1012     if ( retTrap != KErrNone )
       
  1013         {
       
  1014         TRACE_FUNC_EXIT
       
  1015         return retTrap;
       
  1016         }
       
  1017     // 2. Lock the entry in metadata.
       
  1018     TUid pluginUid = aImplInfo->ImplementationUid();
       
  1019     TInt retTemp = iMetadata->LockPluginAccess( pluginUid );
       
  1020     if ( retTemp != KErrNone )
       
  1021         {
       
  1022         TRACE_FUNC_EXIT
       
  1023         return retTemp;
       
  1024         }
       
  1025     // 3. Notify client of installation.
       
  1026     if ( iEcomStatusMessage.Handle() )
       
  1027         {
       
  1028         TPckg<TUid> pluginUidPckg( pluginUid );
       
  1029         retTemp = iEcomStatusMessage.Write(
       
  1030             EATExtReceiveEcomPluginChangeParamUid,
       
  1031             pluginUidPckg );
       
  1032         TRACE_INFO(( _L("Write returned %d"), retTemp ));
       
  1033         TPckg<TATExtensionEcomType> ecomType( EEcomTypeInstall );
       
  1034         retTemp = iEcomStatusMessage.Write(
       
  1035             EATExtReceiveEcomPluginChangeParamType,
       
  1036             ecomType );
       
  1037         TRACE_INFO(( _L("Write returned %d"), retTemp ));
       
  1038         iEcomStatusMessage.Complete( KErrNone );
       
  1039         }
       
  1040     // 4. When client notifies installation, remove the lock from metadata.
       
  1041     // See IpcReportListenerUpdateReady() for this.
       
  1042     TRACE_FUNC_EXIT
       
  1043     return KErrNone;
       
  1044     }
       
  1045 
       
  1046 // ---------------------------------------------------------------------------
       
  1047 // From MATExtListen.
       
  1048 // Notifies about an uninstalled plugin.
       
  1049 // ---------------------------------------------------------------------------
       
  1050 //
       
  1051 TInt CATExtSession::NotifyPluginUninstallation( TUid& /*aIfUid*/,
       
  1052                                                 TUid& aPluginUid )
       
  1053     {
       
  1054     TRACE_FUNC_ENTRY
       
  1055     if ( !iMetadata )
       
  1056         {
       
  1057         TRACE_FUNC_EXIT
       
  1058         return KErrGeneral;
       
  1059         }
       
  1060     // 1. Lock the access to metadata from the responsible plugin UID.
       
  1061     TInt retTemp = iMetadata->LockPluginAccess( aPluginUid );
       
  1062     if ( retTemp != KErrNone )
       
  1063         {
       
  1064         TRACE_FUNC_EXIT
       
  1065         return retTemp;
       
  1066         }
       
  1067     // 2. Notify client of removal.
       
  1068     if ( iEcomStatusMessage.Handle() )
       
  1069         {
       
  1070         TPckg<TUid> pluginUid( aPluginUid );
       
  1071         retTemp = iEcomStatusMessage.Write(
       
  1072             EATExtReceiveEcomPluginChangeParamUid,
       
  1073             pluginUid );
       
  1074         TRACE_INFO(( _L("Write returned %d"), retTemp ));
       
  1075         TPckg<TATExtensionEcomType> ecomType( EEcomTypeUninstall );
       
  1076         retTemp = iEcomStatusMessage.Write(
       
  1077             EATExtReceiveEcomPluginChangeParamType,
       
  1078             ecomType );
       
  1079         TRACE_INFO(( _L("Write returned %d"), retTemp ));
       
  1080         iEcomStatusMessage.Complete( KErrNone );
       
  1081         }
       
  1082     // 3. When client notifies of removal, remove the locked entry from metadata.
       
  1083     // See IpcReportListenerUpdateReady() for this.
       
  1084     TRACE_FUNC_EXIT
       
  1085     return KErrNone;
       
  1086     }