cbsatplugin/atmisccmdplugin/inc/atmisccmdplugin.h
branchRCL_3
changeset 12 b23265fb36da
child 16 95674584745d
equal deleted inserted replaced
11:f7fbeaeb166a 12:b23265fb36da
       
     1 /*
       
     2 * Copyright (c) 2010 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:  Main handler for incoming requests
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef ATMISCCMDPLUGIN_H
       
    19 #define ATMISCCMDPLUGIN_H
       
    20 
       
    21 #include <atextpluginbase.h>
       
    22 #include <etelmm.h>
       
    23 
       
    24 #include "atcommandparser.h"
       
    25 
       
    26 /** Character types: carriage return, line feed or backspace */
       
    27 enum TCharacterTypes
       
    28     {
       
    29     ECharTypeCR,  // Carriage return
       
    30     ECharTypeLF,  // Line feed
       
    31     ECharTypeBS   // Backspace
       
    32     };
       
    33 
       
    34 /** Type of modes (quiet, verbose) */
       
    35 enum TModeTypes
       
    36     {
       
    37     EModeTypeQuiet,   // Quiet mode
       
    38     EModeTypeVerbose  // Verbose mode
       
    39     };
       
    40 
       
    41 
       
    42 class MATMiscCmdPlugin;
       
    43 
       
    44 
       
    45 /**
       
    46  *  Class for common AT command handler interface
       
    47  */
       
    48 NONSHARABLE_CLASS( CATCmdAsyncBase ) : public CActive 
       
    49     {
       
    50 public:
       
    51     virtual ~CATCmdAsyncBase() {};
       
    52     CATCmdAsyncBase(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone);
       
    53 
       
    54     /**
       
    55      * @see CATExtPluginBase::HandleCommand
       
    56      */
       
    57     virtual void HandleCommand( const TDesC8& aCmd,
       
    58                                 RBuf8& aReply,
       
    59                                 TBool aReplyNeeded ) = 0;
       
    60 
       
    61     /**
       
    62      * @see CATExtPluginBase::HandleCommandCancel
       
    63      */
       
    64     virtual void HandleCommandCancel() = 0;
       
    65 
       
    66 protected:
       
    67     MATMiscCmdPlugin* iCallback;
       
    68     TAtCommandParser& iATCmdParser;
       
    69     RMobilePhone& iPhone;
       
    70     };
       
    71 
       
    72 /**
       
    73  *  Class for accessing plugin information and common functionality
       
    74  */
       
    75 NONSHARABLE_CLASS( MATMiscCmdPlugin )
       
    76     {
       
    77 public:
       
    78     /**
       
    79      * Creates an AT command reply based on the reply type and completes the
       
    80      * request to ATEXT.
       
    81      *
       
    82      * @param aReplyType Type of reply
       
    83      * @param aSrcBuffer Source buffer; used only if aReplyType is EReplyTypeOther
       
    84      * @param aError Completion code. If not KErrNone then other arguments are
       
    85      *               ignored and the request is completed to ATEXT with
       
    86      *               EReplyTypeUndefined.
       
    87      * @return Symbian error code on error, KErrNone otherwise
       
    88      */
       
    89     virtual TInt CreateReplyAndComplete( TATExtensionReplyType aReplyType,
       
    90                                          const TDesC8& aSrcBuffer=KNullDesC8,
       
    91                                          TInt aError=KErrNone ) = 0;
       
    92 
       
    93     /**
       
    94      * Creates a buffer for "OK" or "ERROR" reply based on the line settings
       
    95      *
       
    96      * @param aReplyBuffer Destination buffer for the created reply
       
    97      * @param aOkReply ETrue if "OK" reply needed,
       
    98      *                 EFalse if "ERROR" reply needed
       
    99      * @return Symbian error code on error, KErrNone otherwise
       
   100      */
       
   101     virtual TInt CreateOkOrErrorReply( RBuf8& aReplyBuffer,
       
   102                                        TBool aOkReply ) = 0;
       
   103 
       
   104     /*
       
   105      * Complete the AT command request with AT CME error code according to given Symbian error code
       
   106      * @param aError Symbian error code 
       
   107      */
       
   108     virtual void CreateCMEReplyAndComplete(TInt aError) = 0;
       
   109 
       
   110     /**
       
   111      * Returns plugin's character value settings (from CATExtPluginBase)
       
   112      *
       
   113      * @param aCharType Character's type
       
   114      * @param aChar Character's value matching aCharType
       
   115      * @return Symbian error code on error, KErrNone otherwise
       
   116      */
       
   117     virtual TInt GetCharacterValue( TCharacterTypes aCharType, TChar& aChar ) = 0;
       
   118 
       
   119     /**
       
   120      * Returns plugin's mode value settings (from CATExtPluginBase)
       
   121      *
       
   122      * @param aModeType Mode type
       
   123      * @param aMode Mode value matching aModeType
       
   124      * @return Symbian error code on error, KErrNone otherwise
       
   125      */
       
   126     virtual TInt GetModeValue( TModeTypes aModeType, TBool& aMode ) = 0;
       
   127     
       
   128     /**
       
   129      * Returns plugin's response to an unsolicited request
       
   130      *
       
   131      * @param aAT the response to display to the user from unsolicited event
       
   132      * @return Symbian error code on error, KErrNone otherwise
       
   133      */  
       
   134     virtual TInt HandleUnsolicitedRequest(const TDesC8& aAT ) = 0;
       
   135     };
       
   136 
       
   137 /**
       
   138  *  Class for selecting handlers for different AT commands
       
   139  */
       
   140 NONSHARABLE_CLASS( CATMiscCmdPlugin ) : public CATExtPluginBase,
       
   141                                        public MATMiscCmdPlugin
       
   142     {
       
   143 public:
       
   144     static CATMiscCmdPlugin* NewL();
       
   145     virtual ~CATMiscCmdPlugin();
       
   146 
       
   147 private: // methods from base class CATExtPluginBase
       
   148     void ReportConnectionName( const TDesC8& aName );
       
   149     TBool IsCommandSupported( const TDesC8& aCmd );
       
   150     void HandleCommand( const TDesC8& aCmd, RBuf8& aReply, TBool aReplyNeeded );
       
   151     void HandleCommandCancel();
       
   152     TInt NextReplyPartLength();
       
   153     TInt GetNextPartOfReply( RBuf8& aNextReply );
       
   154     void ReceiveUnsolicitedResult();
       
   155     void ReceiveUnsolicitedResultCancel();
       
   156     void ReportNvramStatusChange( const TDesC8& aNvram );
       
   157     void ReportExternalHandleCommandError();
       
   158     
       
   159 private: // methods from base class MATMiscCmdPlugin
       
   160     virtual TInt CreateReplyAndComplete( TATExtensionReplyType aReplyType,
       
   161                                  const TDesC8& aSrcBuffer=KNullDesC8,
       
   162                                  TInt aError=KErrNone );
       
   163 
       
   164     virtual TInt CreateOkOrErrorReply( RBuf8& aReplyBuffer,
       
   165                                TBool aOkReply );
       
   166     virtual void CreateCMEReplyAndComplete(TInt aError);
       
   167     virtual TInt GetCharacterValue( TCharacterTypes aCharType, TChar& aChar );
       
   168     virtual TInt GetModeValue( TModeTypes aModeType, TBool& aMode );    
       
   169     virtual TInt HandleUnsolicitedRequest(const TDesC8& aAT );
       
   170     
       
   171 private:    
       
   172     CATMiscCmdPlugin();
       
   173     void ConstructL();
       
   174     
       
   175     TInt CreatePartOfReply( RBuf8& aBuffer );
       
   176     
       
   177     /*
       
   178      * Utility function that connect to Etel server and establish a subsession to RMobilePhone
       
   179      * Caller must close session and subsession after use.
       
   180      * @param aTelServer returns session to ETel
       
   181      * @param aPhone returns RMobilePhone subsession
       
   182      */
       
   183     void ConnectToEtelL(RTelServer& aTelServer, RMobilePhone& aPhone);
       
   184 
       
   185 
       
   186 private:
       
   187     TAtCommandParser iCommandParser;
       
   188     RTelServer iTelServer;
       
   189     RMobilePhone iPhone;
       
   190     /**
       
   191      * Current AT command handler in.
       
   192      * Used when IsCommandSupported() detects a matching handler class.
       
   193      */
       
   194     CATCmdAsyncBase* iCurrentHandler;
       
   195     
       
   196     CATCmdAsyncBase* iCLCKHandler;
       
   197     CATCmdAsyncBase* iCPWDHandler;
       
   198     CATCmdAsyncBase* iCPINHandler;
       
   199     CATCmdAsyncBase* iCUSDHandler;
       
   200     CATCmdAsyncBase* iCNUMHandler;
       
   201     CATCmdAsyncBase* iCFUNHandler;
       
   202     CATCmdAsyncBase* iCBCHandler;
       
   203     
       
   204     /**
       
   205      * Buffer for handle command's command
       
   206      * Not own.
       
   207      */
       
   208     const TDesC8* iHcCmd;
       
   209 
       
   210     /**
       
   211      * Buffer for handle command reply
       
   212      * Not own.
       
   213      */
       
   214     RBuf8* iHcReply;
       
   215 
       
   216     /**
       
   217      * Global reply buffer for the AT command replies
       
   218      */
       
   219     RBuf8 iReplyBuffer;
       
   220     };
       
   221 
       
   222 #endif  // ATMISCCMDPLUGIN_H
       
   223