sipvoipprovider/svphold/inc/svpholdcontext.h
changeset 0 a4daefaec16c
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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:  Base class for hold contexts. Contains methods 
       
    15 *                for creating the state array and controlling current state.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef SVPHOLDCONTEXT_H
       
    21 #define SVPHOLDCONTEXT_H
       
    22 
       
    23 #include    <e32base.h>
       
    24 #include    <mccpcallobserver.h>
       
    25 #include    "svputdefs.h"
       
    26 
       
    27 // Constants
       
    28 const TInt KSVPHoldDirectionAttributeCount  = 4;    // "sendonly" etc.
       
    29 const TInt KSVPMaxDirectionAttributeLength  = 10;   // "a=sendonly"
       
    30 const TInt KSVPHoldStateArraySize           = 5;
       
    31 const TInt KSVPHoldMaxLengthOfSDPMessage    = 1000;
       
    32 const TInt KSVPHoldMaxLengthOfInetAddr      = 32;
       
    33 
       
    34 // SDP Connection field content for oldway hold
       
    35 _LIT8( KSVPHoldZeroAddr, "0.0.0.0" );
       
    36 
       
    37 // SDP Direction attributes
       
    38 _LIT8( KSVPHoldAttributeSendrecv, "a=sendrecv" );
       
    39 _LIT8( KSVPHoldAttributeSendonly, "a=sendonly" );
       
    40 _LIT8( KSVPHoldAttributeRecvonly, "a=recvonly" );
       
    41 _LIT8( KSVPHoldAttributeInactive, "a=inactive" );
       
    42 
       
    43 // Indexes for direction attributes
       
    44 typedef TInt KSVPHoldAttributeIndex;
       
    45 const KSVPHoldAttributeIndex KSVPHoldSendrecvIndex      = 0;
       
    46 const KSVPHoldAttributeIndex KSVPHoldSendonlyIndex      = 1;
       
    47 const KSVPHoldAttributeIndex KSVPHoldRecvonlyIndex      = 2;
       
    48 const KSVPHoldAttributeIndex KSVPHoldInactiveIndex      = 3;
       
    49 
       
    50 // State indices
       
    51 typedef TInt TSVPHoldStateIndex;
       
    52 const TSVPHoldStateIndex KSVPHoldConnectedStateIndex    = 0;
       
    53 const TSVPHoldStateIndex KSVPHoldEstablishingStateIndex = 1;
       
    54 const TSVPHoldStateIndex KSVPHoldOutStateIndex          = 2;
       
    55 const TSVPHoldStateIndex KSVPHoldInStateIndex           = 3;
       
    56 const TSVPHoldStateIndex KSVPHoldDHStateIndex           = 4;
       
    57 
       
    58 /**
       
    59 * Hold transition
       
    60 */
       
    61 // session hold state, needed for dtmf for determining active session
       
    62 enum TSVPSessionHoldState
       
    63     {
       
    64     ESVPConnected   = 0,
       
    65     ESVPEstablishing,
       
    66     ESVPOnHold
       
    67     };
       
    68     
       
    69 
       
    70 /**
       
    71 * Hold desired state change
       
    72 */    
       
    73 enum TSVPHoldDesiredTransition
       
    74     {
       
    75     ESVPHoldNoRequest           = 0,
       
    76     ESVPHoldToHold              = 1,
       
    77     ESVPHoldToResume            = 2,
       
    78     ESVPHoldIncoming            = 3
       
    79     };
       
    80 
       
    81 /**
       
    82 * Hold request type
       
    83 */    
       
    84 enum TSVPHoldRequestType
       
    85     {
       
    86     ESVPNoType                  = 0,
       
    87     ESVPLocalHold               = 1,
       
    88     ESVPLocalResume             = 2,
       
    89     ESVPLocalDoubleHold         = 3,
       
    90     ESVPLocalDoubleHoldResume   = 4,
       
    91     ESVPRemoteHold              = 5,
       
    92     ESVPRemoteResume            = 6,
       
    93     ESVPRemoteDoubleHold        = 7,
       
    94     ESVPRemoteDoubleHoldResume  = 8,
       
    95     ESVPRequestError            = 9 // causes state to resume previous
       
    96     };
       
    97 
       
    98 /**
       
    99 * Hold state
       
   100 */
       
   101 enum TSVPHoldState
       
   102     {
       
   103     ESVPHoldConnected           = 0,
       
   104     ESVPHoldLocallyHolded       = 1,
       
   105     ESVPHoldRemoteHolded        = 2,
       
   106     ESVPHoldLocallyDoubleHolded = 3,
       
   107     ESVPHoldRemoteDoubleHolded  = 4
       
   108     };
       
   109 
       
   110 
       
   111 class CSdpConnectionField;
       
   112 class TInetAddr;
       
   113 class CDesC8Array;
       
   114 class MDesC8Array;
       
   115 class CMceSession;
       
   116 class TMceTransactionDataContainer;
       
   117 class CSVPHoldStateBase;
       
   118 class MSVPHoldObserver;
       
   119 class CSVPHoldAttributeHandler;
       
   120 class CSVPHoldMediaHandler;
       
   121 
       
   122 
       
   123 /**
       
   124 *  Base class for session contexts.
       
   125 *
       
   126 *  @lib svp.dll
       
   127 *  @since Series 60 3.2
       
   128 */
       
   129 class CSVPHoldContext : public CBase
       
   130     {
       
   131 public:  // Constructors and destructor
       
   132     
       
   133     /**
       
   134     * Two-phased constructor.
       
   135     */
       
   136     static CSVPHoldContext* NewL(
       
   137                         CMceSession& aSession,
       
   138                         TMceTransactionDataContainer& aContainer,
       
   139                         MSVPHoldObserver* iObserver,
       
   140                         TBool aIsMobileOriginated );
       
   141     
       
   142     /**
       
   143     * Destructor.
       
   144     */
       
   145     virtual ~CSVPHoldContext();
       
   146 
       
   147 public: // New functions
       
   148     
       
   149     /**
       
   150     * Sets the current state for the context.
       
   151     * Leaves with Error code if state transition is not acceptable.
       
   152     * @since Series 60 3.2
       
   153     * @param aContext Hold context
       
   154     * @param aNewState New current state
       
   155     */
       
   156     void SetCurrentStateL( CSVPHoldContext& aContext,
       
   157                            TSVPHoldStateIndex aNewState );
       
   158 
       
   159     /**
       
   160     * Returns the current state of the context
       
   161     * @since Series 60 3.2
       
   162     * @return TSVPHoldStateIndex the current state, index to it.
       
   163     */
       
   164     TSVPHoldStateIndex CurrentState() const;
       
   165     
       
   166     /**
       
   167     * Applies the current state of the contex. This causes a
       
   168     * state transition to next state of the state machine. The 
       
   169     * current state sets the next state. Leaves on error
       
   170     * @since Series 60 3.2
       
   171     * @param aSession Session to be modified
       
   172     * @param aTransition Desired operation
       
   173     */
       
   174     void ApplyCurrentStateL( CMceSession* aSession,
       
   175                              TSVPHoldDesiredTransition aTransition );
       
   176 
       
   177     /**
       
   178     * Applies the current state of the contex. This causes a
       
   179     * state transition to next state of the state machine. The 
       
   180     * current state sets the next state. Leaves on error
       
   181     * @since Series 60 3.2
       
   182     */
       
   183     void ApplyCurrentStateL();
       
   184 
       
   185     /**
       
   186     * Sets the reference to session object
       
   187     * state leaves.
       
   188     * @since Series 60 3.2
       
   189     * @param aSession The session object
       
   190     */
       
   191     void SetSessionObject( CMceSession* aSession );
       
   192     
       
   193     /**
       
   194     * Returns reference to session object
       
   195     * state leaves.
       
   196     * @since Series 60 3.2
       
   197     * @return Pointer to session object
       
   198     */
       
   199     CMceSession* SessionObject();
       
   200     
       
   201     /**
       
   202     * Returns type of hold request. This is valid during the complete
       
   203     * state transition process, until next stable state is reached.
       
   204     * @since Series 60 3.2
       
   205     * @return Hold request type
       
   206     */
       
   207     TSVPHoldRequestType HoldRequest();
       
   208     
       
   209     /**
       
   210     * Returns ETrue if hold/resume remote request.
       
   211     * @since Series 60 3.2
       
   212     * @return Boolean value
       
   213     */
       
   214     TBool IsRemoteRequest();
       
   215         
       
   216     /**
       
   217     * After completed & succesful IN / OUT Request, returns occurred event.
       
   218     * @since Series 60 3.2
       
   219     * @return Occurred event to be informed to client application
       
   220     */
       
   221     MCCPCallObserver::TCCPCallEvent HoldEvent();
       
   222     
       
   223     /**
       
   224     * Sets first attempt flag
       
   225     * @since Series 60 3.2
       
   226     * @param aValue Boolean value for -flag
       
   227     */
       
   228     void SetFirstAttempt( TBool aValue );
       
   229     
       
   230     /**
       
   231     * Returns value of first attempt -flag
       
   232     * @since Series 60 3.2
       
   233     * @return Boolean value of first attempt -flag
       
   234     */
       
   235     TBool FirstAttempt();
       
   236     
       
   237     /**
       
   238     * Sets remote request not processed -flag
       
   239     * @since Series 60 3.2
       
   240     * @param aValue Boolean value for flag
       
   241     */
       
   242     void SetRemoteRequestNotProcessed( TBool aValue );
       
   243     
       
   244     /**
       
   245     * Returns value of the remote request not processed -flag
       
   246     * @since Series 60 3.2
       
   247     * @return Boolean value of the remote request not processed -flag
       
   248     */
       
   249     TBool RemoteRequestNotProcessed();
       
   250             
       
   251     /**
       
   252     * Sets audio handling allowed -flag
       
   253     * @since Series 60 3.2
       
   254     * @param aValue Boolean value for flag
       
   255     */
       
   256     void SetAudioHandlingAllowed( TBool aValue );
       
   257 
       
   258     /**
       
   259     * Returns value of the audio handling allowed -flag
       
   260     * @since Series 60 3.2
       
   261     * @return Boolean value of the audio handling allowed -flag
       
   262     */
       
   263     TBool AudioHandlingAllowed();
       
   264     
       
   265     /**
       
   266     * Returns reference to hold observer.
       
   267     * @since Series 60 3.2
       
   268     * @return Reference to hold observer.
       
   269     */
       
   270     MSVPHoldObserver& HoldObserver();
       
   271         
       
   272     /**
       
   273     * Returns reference to attribute handler.
       
   274     * @since Series 60 3.2
       
   275     * @return Reference to attribute handler.
       
   276     */
       
   277     CSVPHoldAttributeHandler& AttributeHandler();
       
   278     
       
   279     /**
       
   280     * Returns reference to media handler.
       
   281     * @since Series 60 3.2
       
   282     * @return Reference to media handler.
       
   283     */
       
   284     CSVPHoldMediaHandler& MediaHandler();
       
   285     
       
   286     /**
       
   287     * Solves type of incoming request and returns next state of state machine.
       
   288     * @since Series 60 3.2
       
   289     * @param aSession Incoming updated MCE session
       
   290     * @param aAttributeLines Attribute lines from incoming request.
       
   291     * @param aCheckOldwayHold ETrue if oldwayhold need to be taken into account
       
   292     * @return TSVPHoldRequestType Request type
       
   293     */
       
   294     TSVPHoldRequestType SolveRequestL( CMceSession& aSession,
       
   295                                        MDesC8Array* aAttributeLines,
       
   296                                        TBool aCheckOldwayHold = EFalse );
       
   297                                        
       
   298     /**
       
   299     * Sets response status code
       
   300     * @since Series 60 3.2
       
   301     * @param aStatusCode Status code of response received
       
   302     */
       
   303     void SetResponseStatusCode( TInt aStatusCode );
       
   304     
       
   305     /**
       
   306     * Gets response status code
       
   307     * @since Series 60 3.2
       
   308     * @return Status code
       
   309     */
       
   310     TInt ResponseStatusCode();
       
   311     
       
   312     /**
       
   313     * Sets force hold flag value
       
   314     * @since Series 60 3.2
       
   315     * @param aForceHold Boolean value
       
   316     */
       
   317     void SetForceHold( TBool aForceHold );
       
   318     
       
   319     /**
       
   320     * Gets force hold flag value
       
   321     * @since Series 60 3.2
       
   322     * @return Boolean value
       
   323     */
       
   324     TBool ForceHoldOccured();
       
   325     
       
   326     /**
       
   327     * Handles and controls hold operation based on response status
       
   328     * @since Series 60 3.2
       
   329     * @param aNextState Valid hold state machine state after function call
       
   330     * @return Boolean value ETrue if response needed special handling
       
   331     */
       
   332     TBool SpecialResponseHandling( TSVPHoldStateIndex& aNextState );
       
   333     
       
   334     /**
       
   335     * Sets hold/resume request timed out -flag,
       
   336     * called when hold/resume request has expired.
       
   337     * @since Series 60 3.2
       
   338     */
       
   339     void TimedOut();
       
   340     
       
   341     /**
       
   342     * Returns RollBack -boolean value
       
   343     * @since Series 60 3.2
       
   344     * @return Boolean value
       
   345     */
       
   346     TBool HoldRolledBack();
       
   347     
       
   348     /**
       
   349     * Sets crossover situation on/off
       
   350     * @since Series 60 3.2
       
   351     * @param ETrue if CrossOver situation, EFalse otherways
       
   352     * @return
       
   353     */
       
   354     void CrossOver( TBool aActive );
       
   355 
       
   356     /**
       
   357     * Returns Hold failed -boolean value. After this function call
       
   358     * flag is cleared.
       
   359     * @since Series 60 3.2
       
   360     * @return ETrue if hold failed, EFalse otherways
       
   361     */
       
   362     TBool HoldFailed();
       
   363 
       
   364     /**
       
   365     * Returns Resume failed -boolean value
       
   366     * @since Series 60 3.2
       
   367     * @return ETrue if resume failed, EFalse otherways
       
   368     */
       
   369     TBool ResumeFailed();
       
   370     
       
   371     /**
       
   372     * Returns IsMobileOriginated -boolean value
       
   373     * @since Series 60 3.2
       
   374     * @return ETrue if MobileOriginated, EFalse otherways
       
   375     */
       
   376     TBool IsMobileOriginated();
       
   377 
       
   378     /**
       
   379     * Sets mute state to Hold Controller
       
   380     * @since Series 60 3.2
       
   381     * @param aMuted Boolean value for mute value
       
   382     */
       
   383     void Muted( TBool aMuted );
       
   384 
       
   385     /**
       
   386     * Returns mute state
       
   387     * @since Series 60 3.2
       
   388     * @return Boolean value for mute value
       
   389     */
       
   390     TBool Muted();
       
   391     
       
   392     /**
       
   393     * Sets CallRequestFailed status ETrue/EFalse
       
   394     * @since Series 60 3.2
       
   395     * @param aCallRequest Boolean value for call on hold request failed
       
   396     */
       
   397     void SetCallRequestFailed( TBool aCallRequest );
       
   398     
       
   399 
       
   400     /**
       
   401     * Returns CallRequestFailed -boolean value
       
   402     * @since Series 60 3.2
       
   403     * @return ETrue if call on hold request failed, EFalse otherways
       
   404     */
       
   405     TBool CallRequestFailed();
       
   406     
       
   407     
       
   408 protected:  // New functions
       
   409 
       
   410     /**
       
   411     * Creates the states belonging to this context
       
   412     * @since Series 60 3.2
       
   413     */
       
   414     void InitializeStateArrayL();
       
   415 
       
   416     /**
       
   417     * Checkes if a state transition to a given state is accepted.
       
   418     * @since Series 60 3.2
       
   419     * @param TSVPHoldStateIndex aStateIndex
       
   420     * @return TBool, boolean value, is the transition valid.
       
   421     */
       
   422     TBool IsStateTransitionAccepted( 
       
   423                         const TSVPHoldStateIndex aStateIndex );
       
   424 
       
   425     /**
       
   426     * C++ default constructor.
       
   427     */
       
   428     CSVPHoldContext( TMceTransactionDataContainer& aContainer,
       
   429                      TBool aIsMobileOriginated );
       
   430 
       
   431     /**
       
   432     * By default Symbian 2nd phase constructor is private. 
       
   433     * Now it is protected.
       
   434     */
       
   435     void ConstructL( CMceSession& aSession,
       
   436                      MSVPHoldObserver* iObserver );
       
   437 
       
   438 
       
   439 private:     // New functions
       
   440     
       
   441     /**
       
   442     * Returns ETrue if establishing state is next, EFalse otherways
       
   443     */
       
   444     TBool ToEstablishing();
       
   445     
       
   446     /**
       
   447     * Returns hold request type
       
   448     */
       
   449     TSVPHoldRequestType RequestType( 
       
   450             TSVPHoldDesiredTransition aTransition );
       
   451             
       
   452     /**
       
   453     * Returns hold request type
       
   454     */
       
   455     TSVPHoldRequestType RequestToHold();
       
   456     
       
   457     /**
       
   458     * Returns hold request type
       
   459     */
       
   460     TSVPHoldRequestType RequestToResume();
       
   461     
       
   462     /**
       
   463     * Returns hold request type
       
   464     */
       
   465     TSVPHoldRequestType RequestIncoming();
       
   466                          
       
   467     /**
       
   468     * Updates right establishing state based on the direction of the request
       
   469     */
       
   470     void UpdateEstablishingStateL();
       
   471     
       
   472     /**
       
   473     * 
       
   474     */
       
   475     TSVPHoldRequestType SolveRequestType( 
       
   476             TInt aAttributeIndex,
       
   477             TSVPHoldRequestType aPresumedRequest );
       
   478                                                                
       
   479     /**
       
   480     * This method is used in mobile terminating(MT) calls, to check SDP
       
   481     * body for Connection field, and to check the content of that field.
       
   482     *
       
   483     * @since    Series60 3.2
       
   484     * @param    aSession Incoming updated MCE session
       
   485     * @param    aPresumedRequest Enumeration for hold request type,
       
   486     *                            assumed hold type passed as parameter.
       
   487     * @return                    Enumerated value of hold request, after
       
   488     *                            oldway hold is checked from the content.
       
   489     */
       
   490     TSVPHoldRequestType 
       
   491     CheckOldwayHoldL( CMceSession& session,
       
   492                       TSVPHoldRequestType aPresumedRequest );
       
   493     
       
   494     /**
       
   495     * Rolls hold session state back to previous state
       
   496     */
       
   497     void RollBack( TSVPHoldStateIndex& aNextState );
       
   498 
       
   499         
       
   500 protected:  // Data
       
   501 
       
   502     // State array
       
   503     RPointerArray< CSVPHoldStateBase >* iStates;
       
   504 
       
   505     // Observer
       
   506     MSVPHoldObserver* iObserver;
       
   507     
       
   508 
       
   509 private:    // Data
       
   510 
       
   511     // Current state
       
   512     CSVPHoldStateBase* iCurrentState;
       
   513     
       
   514     // Current hold request type. Changed by SolveRequestType() and
       
   515     // in special cases, e.g. when 2-phased hold needed (MO oldway)
       
   516     TSVPHoldRequestType iHoldRequest;
       
   517     
       
   518     // Pointer to session object (not owned)
       
   519     CMceSession* iSession;
       
   520     
       
   521     // Boolean value of request direction
       
   522     TBool iOutgoing;
       
   523     
       
   524     // Instance of attribute handler
       
   525     CSVPHoldAttributeHandler* iAttributeHandler;
       
   526     
       
   527     // Instance of media handler
       
   528     CSVPHoldMediaHandler* iMediaHandler;
       
   529     
       
   530     // First attempt (not MO oldway hold)
       
   531     TBool iFirstAttempt;
       
   532     
       
   533     // Flag for remote request in process
       
   534     TBool iRemoteRequestNotProcessed;
       
   535     
       
   536     // Data container for mce session
       
   537     TMceTransactionDataContainer& iContainer;
       
   538     
       
   539     // Hold event
       
   540     MCCPCallObserver::TCCPCallEvent iHoldEvent;
       
   541     
       
   542     // Indicates that audio handling is allowed
       
   543     TBool iAllowAudioHandling;
       
   544     
       
   545     // Status code of the response
       
   546     TInt iResponseStatusCode;
       
   547     
       
   548     // Force hold occured flag;
       
   549     TBool iForceHoldOccured;
       
   550     
       
   551     // Flag for timed out hold/resume request
       
   552     TBool iTimedOut;
       
   553     
       
   554     // Flag for preventing audio enable/disable
       
   555     TBool iRollBack;
       
   556     
       
   557     // Flag for failed hold
       
   558     TBool iHoldFail;
       
   559     
       
   560     // Flag for failed resume (causes session to be terminated)
       
   561     TBool iResumeFail;
       
   562     
       
   563     // Flag for SVP session direction
       
   564     TBool iIsMobileOriginated;
       
   565     
       
   566     // Flag for mute
       
   567     TBool iMuted;
       
   568     
       
   569     // Flag for cross over (simultaneous requests)
       
   570     TBool iCrossOver;
       
   571     
       
   572     // Flag for callbackrequest
       
   573     TBool iCallRequest;
       
   574 
       
   575 
       
   576 private:
       
   577     
       
   578     // For testing
       
   579     SVP_UT_DEFS
       
   580     
       
   581     };
       
   582 
       
   583 #endif      // SVPHOLDCONTEXT_H 
       
   584