atext/client/src/atextclient.cpp
changeset 0 29b1cd4cb562
child 1 b4a7eebaaebf
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 /*
       
     2 * Copyright (c) 2008-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:  AT extension client implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <atext.h>
       
    20 #include "atextclientsrv.h"
       
    21 #include "atext_interfaceuid.h"
       
    22 #include "debug.h"
       
    23 
       
    24 _LIT( KATExtSrvExe, "atext.exe" );
       
    25 
       
    26 const TUid KATExtSrvUid3 = { 0x2001CBEB };
       
    27 
       
    28 static TInt StartServer();
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // Establishes a session with server and connect to corresponding extension
       
    32 // plugins specified by parameter TATExtensionInterface.
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 EXPORT_C TInt RATExt::Connect( TATExtensionInterface aIf,
       
    36                                const TDesC8& aName )
       
    37     {
       
    38     TRACE_FUNC_ENTRY
       
    39     TVersion version( KServerMajorVersionNumber,
       
    40                       KServerMinorVersionNumber,
       
    41                       KServerBuildVersionNumber );
       
    42 
       
    43     TInt retVal = CreateSession( KATExtSrvName, version );
       
    44     if ( retVal!=KErrNone && retVal!=KErrAlreadyExists )
       
    45         {
       
    46         retVal = StartServer();
       
    47         if ( retVal==KErrNone || retVal==KErrAlreadyExists )
       
    48             {
       
    49             retVal = CreateSession( KATExtSrvName, version );
       
    50             }
       
    51         }
       
    52 
       
    53     TRACE_INFO((_L("ret %d "), retVal))
       
    54     if ( retVal==KErrNone || retVal==KErrAlreadyExists )
       
    55         {
       
    56         TUid ifUid = TUid::Null();
       
    57         if ( aIf == EHfpATExtension )
       
    58             {
       
    59             ifUid.iUid = ATEXT_INTERFACE_HFP_UID;
       
    60             }
       
    61         else if ( aIf == EDunATExtension )
       
    62             {
       
    63             ifUid.iUid = ATEXT_INTERFACE_DUN_UID;
       
    64             }
       
    65         TPckg<TUid> ifUidPckg( ifUid );
       
    66         retVal = SendReceive( EATExtSetExtensionInterface,
       
    67                               TIpcArgs(&ifUidPckg,&aName) );
       
    68         }
       
    69     if ( retVal != KErrNone )
       
    70         {
       
    71         Close();
       
    72         }
       
    73     else
       
    74         {
       
    75         iConnectedIf = aIf;
       
    76         }
       
    77     TRACE_FUNC_EXIT
       
    78     return retVal;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // Synchronously closes the session
       
    83 // Optional: client can do either Close() or SynchronousClose()+Close()
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 EXPORT_C TInt RATExt::SynchronousClose()
       
    87     {
       
    88     TRACE_FUNC_ENTRY
       
    89     if ( !Handle() )
       
    90         {
       
    91         TRACE_FUNC_EXIT
       
    92         return KErrBadHandle;
       
    93         }
       
    94     TInt retVal = SendReceive( EATExtSynchronousClose );
       
    95     TRACE_FUNC_EXIT
       
    96     return retVal;
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // Handles a command.
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 EXPORT_C TInt RATExt::HandleCommand(
       
   104     TRequestStatus& aStatus,
       
   105     const TDesC8& aCmd,
       
   106     TBuf8<KDefaultCmdBufLength>& aReply,
       
   107     TPckg<TInt>& aRemainingReplyLength,
       
   108     TPckg<TATExtensionReplyType>& aReplyType )
       
   109     {
       
   110     TRACE_FUNC_ENTRY
       
   111     if ( !Handle() )
       
   112         {
       
   113         TRequestStatus* status = &aStatus;
       
   114         aStatus = KRequestPending;
       
   115         User::RequestComplete( status, KErrBadHandle );
       
   116         TRACE_FUNC_EXIT
       
   117         return KErrBadHandle;
       
   118         }
       
   119     aStatus = KRequestPending;
       
   120     SendReceive( EATExtHandleCommand,
       
   121                  TIpcArgs(&aCmd,&aReply,&aRemainingReplyLength,&aReplyType),
       
   122                  aStatus );
       
   123     TRACE_FUNC_EXIT
       
   124     return KErrNone;
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // Cancels a command handling request.
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C TInt RATExt::CancelHandleCommand()
       
   132     {
       
   133     TRACE_FUNC_ENTRY
       
   134     if ( !Handle() )
       
   135         {
       
   136         TRACE_FUNC_EXIT
       
   137         return KErrBadHandle;
       
   138         }
       
   139     TInt retVal = SendReceive( EATExtCancelHandleCommand );
       
   140     TRACE_FUNC_EXIT
       
   141     return retVal;
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // Gets the remaining reply of a previous handled command.
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 EXPORT_C TInt RATExt::GetNextPartOfReply( TBuf8<KDefaultCmdBufLength>& aReply,
       
   149                                           TInt& aRemainingReplyLength )
       
   150     {
       
   151     TRACE_FUNC_ENTRY
       
   152     if ( !Handle() )
       
   153         {
       
   154         TRACE_FUNC_EXIT
       
   155         return KErrBadHandle;
       
   156         }
       
   157     TPckg<TInt> remainingLength( aRemainingReplyLength );
       
   158     TInt retVal = SendReceive( EATExtGetNextPartOfReply,
       
   159                                TIpcArgs(&aReply,&remainingLength) );
       
   160     TRACE_FUNC_EXIT
       
   161     return retVal;
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // Number of plugins
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 EXPORT_C TInt RATExt::NumberOfPlugins()
       
   169     {
       
   170     TRACE_FUNC_ENTRY
       
   171     if ( !Handle() )
       
   172         {
       
   173         TRACE_FUNC_EXIT
       
   174         return KErrBadHandle;
       
   175         }
       
   176     TInt retVal = SendReceive( EATExtNumberOfPlugins );
       
   177     TRACE_FUNC_EXIT
       
   178     return retVal;
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // Receives unsolicited result code from extension plugins.
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 EXPORT_C TInt RATExt::ReceiveUnsolicitedResult( TRequestStatus& aStatus,
       
   186                                                 TBuf8<KDefaultUrcBufLength>& aRecvBuffer,
       
   187                                                 TPckg<TUid>& aUrcPluginUid )
       
   188     {
       
   189     TRACE_FUNC_ENTRY
       
   190     if ( !Handle() )
       
   191         {
       
   192         TRequestStatus* status = &aStatus;
       
   193         aStatus = KRequestPending;
       
   194         User::RequestComplete( status, KErrBadHandle );
       
   195         TRACE_FUNC_EXIT
       
   196         return KErrBadHandle;
       
   197         }
       
   198     aStatus = KRequestPending;
       
   199     SendReceive( EATExtReceiveUnsolicitedResult,
       
   200                  TIpcArgs(&aRecvBuffer,&aUrcPluginUid),
       
   201                  aStatus );
       
   202     TRACE_FUNC_EXIT
       
   203     return KErrNone;
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // Cancels a pending receiving request.
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 EXPORT_C TInt RATExt::CancelReceiveUnsolicitedResult( TUid& aUrcPluginUid )
       
   211     {
       
   212     TRACE_FUNC_ENTRY
       
   213     if ( !Handle() )
       
   214         {
       
   215         TRACE_FUNC_EXIT
       
   216         return KErrBadHandle;
       
   217         }
       
   218     TPckg<TUid> urcPluginUid( aUrcPluginUid );
       
   219     TInt retVal = SendReceive( EATExtCancelReceiveUnsolicitedResult,
       
   220                                TIpcArgs(&urcPluginUid) );
       
   221     TRACE_FUNC_EXIT
       
   222     return retVal;
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // Marks URC handling ownership.
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 EXPORT_C TInt RATExt::MarkUrcHandlingOwnership( TUid& aUrcPluginUid )
       
   230     {
       
   231     TRACE_FUNC_ENTRY
       
   232     if ( !Handle() )
       
   233         {
       
   234         TRACE_FUNC_EXIT
       
   235         return KErrBadHandle;
       
   236         }
       
   237     TPckg<TUid> urcPluginUid( aUrcPluginUid );
       
   238     TInt retVal = SendReceive( EATExtMarkUrcHandlingOwnership,
       
   239                                TIpcArgs(&urcPluginUid) );
       
   240     TRACE_FUNC_EXIT
       
   241     return retVal;
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // Receives ECOM plugin uninstall/install/version reports
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 EXPORT_C TInt RATExt::ReceiveEcomPluginChange(
       
   249     TRequestStatus& aStatus,
       
   250     TPckg<TUid>& aPluginUid,
       
   251     TPckg<TATExtensionEcomType>& aEcomType )
       
   252     {
       
   253     TRACE_FUNC_ENTRY
       
   254     if ( !Handle() )
       
   255         {
       
   256         TRequestStatus* status = &aStatus;
       
   257         aStatus = KRequestPending;
       
   258         User::RequestComplete( status, KErrBadHandle );
       
   259         TRACE_FUNC_EXIT
       
   260         return KErrBadHandle;
       
   261         }
       
   262     aStatus = KRequestPending;
       
   263     SendReceive( EATExtReceiveEcomPluginChange,
       
   264                  TIpcArgs(&aPluginUid,&aEcomType),
       
   265                  aStatus );
       
   266     TRACE_FUNC_EXIT
       
   267     return KErrNone;
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // Cancels ECOM plugin uninstall/install/version report receiving
       
   272 // ---------------------------------------------------------------------------
       
   273 //
       
   274 EXPORT_C TInt RATExt::CancelReceiveEcomPluginChange()
       
   275     {
       
   276     TRACE_FUNC_ENTRY
       
   277     if ( !Handle() )
       
   278         {
       
   279         TRACE_FUNC_EXIT
       
   280         return KErrBadHandle;
       
   281         }
       
   282     TInt retVal = SendReceive( EATExtCancelReceiveEcomPluginChange );
       
   283     TRACE_FUNC_EXIT
       
   284     return retVal;
       
   285     }
       
   286 
       
   287 // ---------------------------------------------------------------------------
       
   288 // Reports change to quiet mode
       
   289 // ---------------------------------------------------------------------------
       
   290 //
       
   291 EXPORT_C TInt RATExt::ReportQuietModeChange( TBool aMode )
       
   292     {
       
   293     TRACE_FUNC_ENTRY
       
   294     if ( !Handle() )
       
   295         {
       
   296         TRACE_FUNC_EXIT
       
   297         return KErrBadHandle;
       
   298         }
       
   299     TPckg<TBool> mode( aMode );
       
   300     TInt retVal = SendReceive( EATExtReportQuietModeChange,
       
   301                                TIpcArgs(&mode) );
       
   302     TRACE_FUNC_EXIT
       
   303     return retVal;
       
   304     }
       
   305 
       
   306 // ---------------------------------------------------------------------------
       
   307 // Reports change to verbose mode
       
   308 // ---------------------------------------------------------------------------
       
   309 //
       
   310 EXPORT_C TInt RATExt::ReportVerboseModeChange( TBool aMode )
       
   311     {
       
   312     TRACE_FUNC_ENTRY
       
   313     if ( !Handle() )
       
   314         {
       
   315         TRACE_FUNC_EXIT
       
   316         return KErrBadHandle;
       
   317         }
       
   318     TPckg<TBool> mode( aMode );
       
   319     TInt retVal = SendReceive( EATExtReportVerboseModeChange,
       
   320                                TIpcArgs(&mode) );
       
   321     TRACE_FUNC_EXIT
       
   322     return retVal;
       
   323     }
       
   324 
       
   325 // ---------------------------------------------------------------------------
       
   326 // Reports change to a value of a character
       
   327 // ---------------------------------------------------------------------------
       
   328 //
       
   329 EXPORT_C TInt RATExt::ReportCharacterChange( TATExtensionCharType aCharType,
       
   330                                              TInt8 aNewChar )
       
   331     {
       
   332     TRACE_FUNC_ENTRY
       
   333     if ( !Handle() )
       
   334         {
       
   335         TRACE_FUNC_EXIT
       
   336         return KErrBadHandle;
       
   337         }
       
   338     TPckg<TATExtensionCharType> charType( aCharType );
       
   339     TPckg<TInt8> newChar( aNewChar );
       
   340     TInt retVal = SendReceive( EATExtReportCharacterChange,
       
   341                                TIpcArgs(&charType,&newChar) );
       
   342     TRACE_FUNC_EXIT
       
   343     return retVal;
       
   344     }
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 // Reporter for reporting when client side has updated its internal
       
   348 // information after ReceiveEcomPluginChange()
       
   349 // ---------------------------------------------------------------------------
       
   350 //
       
   351 EXPORT_C TInt RATExt::ReportListenerUpdateReady(
       
   352     TUid& aPluginUid,
       
   353     TATExtensionEcomType aUpdateType )
       
   354     {
       
   355     TRACE_FUNC_ENTRY
       
   356     if ( !Handle() )
       
   357         {
       
   358         TRACE_FUNC_EXIT
       
   359         return KErrBadHandle;
       
   360         }
       
   361     TPckg<TUid> pluginUid( aPluginUid );
       
   362     TPckg<TATExtensionEcomType> updateType( aUpdateType );
       
   363     TInt retVal = SendReceive( EATExtReportListenerUpdateReady,
       
   364                                TIpcArgs(&pluginUid,&updateType) );
       
   365     TRACE_FUNC_EXIT
       
   366     return retVal;
       
   367     }
       
   368 
       
   369 // ---------------------------------------------------------------------------
       
   370 // Broadcasts NVRAM status change to the plugins.
       
   371 // ---------------------------------------------------------------------------
       
   372 //
       
   373 EXPORT_C TInt RATExt::BroadcastNvramStatusChange( const TDesC8& aNvram )
       
   374     {
       
   375     TRACE_FUNC_ENTRY
       
   376     if ( !Handle() )
       
   377         {
       
   378         TRACE_FUNC_EXIT
       
   379         return KErrBadHandle;
       
   380         }
       
   381     TInt retVal = SendReceive( EATExtBroadcastNvramStatusChange,
       
   382                                TIpcArgs(&aNvram) );
       
   383     TRACE_FUNC_EXIT
       
   384     return retVal;
       
   385     }
       
   386 
       
   387 // ---------------------------------------------------------------------------
       
   388 // Reports about external handle command error condition.
       
   389 // This is for cases when for example DUN decided the reply contained an
       
   390 // error condition but the plugin is still handling the command internally.
       
   391 // Example: "AT+TEST;+TEST2" was given in command line; "AT+TEST" returns
       
   392 // non-EReplyTypeError condition and "AT+TEST2" returns EReplyTypeError.
       
   393 // As the plugin(s) returning the non-EReplyTypeError may still have some
       
   394 // ongoing operation then these plugins are notified about the external
       
   395 // EReplyTypeError in command line processing. It is to be noted that
       
   396 // HandleCommandCancel() is not sufficient to stop the processing as the
       
   397 // command handling has already finished.
       
   398 // ---------------------------------------------------------------------------
       
   399 //
       
   400 EXPORT_C TInt RATExt::ReportExternalHandleCommandError()
       
   401     {
       
   402     TRACE_FUNC_ENTRY
       
   403     if ( !Handle() )
       
   404         {
       
   405         TRACE_FUNC_EXIT
       
   406         return KErrBadHandle;
       
   407         }
       
   408     TInt retVal = SendReceive( EATExtReportExternalHandleCommandError );
       
   409     TRACE_FUNC_EXIT
       
   410     return retVal;
       
   411     }
       
   412 
       
   413 // ---------------------------------------------------------------------------
       
   414 // Reports about abort condition in command handling.
       
   415 // This is for cases when for example DUN decided an abort condition was
       
   416 // received from DTE (ITU-T V.250 5.6.1). This API is for notifying the
       
   417 // plugin that abort was requested. However the plugin currently handling
       
   418 // the command may ignore the request if it doesn't support abort for the
       
   419 // command or it may return the changed condition with
       
   420 // HandleCommandCompleted()
       
   421 // ---------------------------------------------------------------------------
       
   422 //
       
   423 EXPORT_C TInt RATExt::ReportHandleCommandAbort( TBool& aStop )
       
   424     {
       
   425     TRACE_FUNC_ENTRY
       
   426     if ( !Handle() )
       
   427         {
       
   428         TRACE_FUNC_EXIT
       
   429         return KErrBadHandle;
       
   430         }
       
   431     TPckg<TBool> stop( aStop );
       
   432     TInt retVal = SendReceive( EATExtReportHandleCommandAbort,
       
   433                                TIpcArgs(&stop) );
       
   434     TRACE_FUNC_EXIT
       
   435     return retVal;
       
   436     }
       
   437 
       
   438 // ---------------------------------------------------------------------------
       
   439 // Gets the next special command RSS file entry. These commands are commands
       
   440 // with a matching start but with any ending sequence. Command "ATD*99***1#"
       
   441 // is one of these and the number of these commands should be kept minimal.
       
   442 // ---------------------------------------------------------------------------
       
   443 //
       
   444 EXPORT_C TInt RATExt::GetNextSpecialCommand( TDes8& aCmd,
       
   445                                              TBool& aFirstSearch )
       
   446     {
       
   447     TRACE_FUNC_ENTRY
       
   448     if ( !Handle() )
       
   449         {
       
   450         TRACE_FUNC_EXIT
       
   451         return KErrBadHandle;
       
   452         }
       
   453     TPckg<TBool> firstSearch( aFirstSearch );
       
   454     TInt retVal = SendReceive( EATExtGetNextSpecialCommand,
       
   455                                TIpcArgs(&aCmd,&firstSearch) );
       
   456     TRACE_FUNC_EXIT
       
   457     return retVal;
       
   458     }
       
   459 
       
   460 // ---------------------------------------------------------------------------
       
   461 // Starts the server
       
   462 // ---------------------------------------------------------------------------
       
   463 //
       
   464 TInt StartServer()
       
   465     {
       
   466     TRACE_STATIC_FUNC
       
   467     const TUidType serverUid( KNullUid, KNullUid, KATExtSrvUid3 );
       
   468     RProcess server;
       
   469     TInt retTemp = server.Create( KATExtSrvExe, KNullDesC, serverUid );
       
   470     server.SetPriority( EPriorityHigh );
       
   471     if ( retTemp != KErrNone )
       
   472         {
       
   473         return retTemp;
       
   474         }
       
   475     TRequestStatus status;
       
   476     server.Rendezvous( status );
       
   477     if ( status != KRequestPending )
       
   478         {
       
   479         server.Kill( 0 );
       
   480         }
       
   481     else
       
   482         {
       
   483         server.Resume();
       
   484         }
       
   485     User::WaitForRequest( status );
       
   486     TRACE_INFO((_L("Server started, code %d"), status.Int()))
       
   487     retTemp = ( server.ExitType() == EExitPanic ) ? KErrGeneral : status.Int();
       
   488     server.Close();
       
   489     return retTemp;
       
   490     }