simpleengine/siputils/inc/simplerequest.h
changeset 0 c8caa15ef882
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 2006 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:    SIMPLE engine request
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef CSimpleRequest_H
       
    22 #define CSimpleRequest_H
       
    23 
       
    24 
       
    25 // INCLUDES
       
    26 #include <e32base.h>
       
    27 #include "simplecommon.h"
       
    28 #include "simplesipconncallback.h"
       
    29 #include "simplecommon.h"
       
    30 #include "msimpleenginerequest.h"
       
    31 #include "simplerefreshtimer.h"
       
    32 
       
    33 // FORWARD DECLARATIONS
       
    34 class CSimpleSipProfileObserver;
       
    35 class CSIPClientTransaction;
       
    36 class CSIPSubscribeDialogAssoc;
       
    37 class CSimpleRefreshTimer;
       
    38 class CSIPRefresh;
       
    39 
       
    40 // CLASS DECLARATION
       
    41 
       
    42 /**
       
    43  * Client request buffer element
       
    44  *
       
    45  * @lib siputils
       
    46  * @since S60 3.2
       
    47  */
       
    48 class CSimpleRequest : public CBase
       
    49 {
       
    50 public:
       
    51 
       
    52 /** request type */
       
    53 enum TSimpleSipReqType
       
    54     {
       
    55     EReqRegister=1,
       
    56     EReqPublish,
       
    57     EReqSubscribe,
       
    58     EReqSubscribeList,
       
    59     EReqSubscribeWinfo,
       
    60     EReqListenEvents,
       
    61     EReqSendIM,
       
    62     EReqReceiveIM
       
    63     };
       
    64 
       
    65 /** request state */
       
    66 enum TSimpleReqState
       
    67     {
       
    68     ESimpleInit=1,
       
    69     ESimplePendingInit,
       
    70     ESimpleRunningInit,
       
    71     ESimpleActive,
       
    72     ESimpleComplete,
       
    73     ESimpleFailed,
       
    74     ESimpleStopping,
       
    75     ESimplePending,
       
    76     ESimpleReTry,
       
    77     ESimpleRunning,
       
    78     ESimpleActiveSubs,
       
    79     ESimpleDialogReCre,
       
    80     ESimpleDeleting
       
    81     };
       
    82    
       
    83 /** pending state substate */    
       
    84 enum TSimplePendingSubState
       
    85     {
       
    86     ENoPending=0,
       
    87     EPendingModify,
       
    88     EPendingRefresh,
       
    89     EPendingModifyAndRefresh
       
    90     }; 
       
    91     
       
    92 
       
    93     /**
       
    94      * Contructor
       
    95      * @param aEngine engine api callback implementation
       
    96      * @param aReq client request
       
    97      * @param aType request type
       
    98      * @param aExpires SIP expiry time of the request 
       
    99      */
       
   100     static CSimpleRequest* NewL(
       
   101         MSimpleSipConnCallback& aEngine,
       
   102         MSimpleEngineRequest& aReq,
       
   103         TSimpleSipReqType aType,
       
   104         TUint aExpires );
       
   105 
       
   106     /**
       
   107      * Destructor
       
   108      */
       
   109     void Destroy();
       
   110 
       
   111     /**
       
   112      * Destructor
       
   113      */
       
   114     void DestroyStart();
       
   115     
       
   116     inline static TInt LinkOffset();       
       
   117 
       
   118     /**
       
   119      * Client request accessor
       
   120      *
       
   121      * @since S60 3.2
       
   122      * @return client request
       
   123      */
       
   124     MSimpleEngineRequest& Request();
       
   125 
       
   126     /**
       
   127      * Client SIP transaction accessor
       
   128      *
       
   129      * @since S60 3.2     
       
   130      * @return SIP transaction, may be NULL.
       
   131      */
       
   132     CSIPClientTransaction* Transaction();
       
   133 
       
   134     /**
       
   135      * Client SIP transaction setter
       
   136      *
       
   137      * @since S60 3.2     
       
   138      * @param aTrans SIP transaction
       
   139      */
       
   140     void SetTransaction( CSIPClientTransaction* aTrans );
       
   141 
       
   142     /**
       
   143      * CSIPRefresh entity accessor
       
   144      *
       
   145      * @since S60 3.2     
       
   146      * @return CSIPRefresh entity
       
   147      */
       
   148     CSIPRefresh* Refresh();
       
   149 
       
   150     /**
       
   151      * If the request matches with the transaction
       
   152      *
       
   153      * @since S60 3.2     
       
   154      * @param aTrans transaction
       
   155      * @return ETrue if matches
       
   156      */
       
   157     TBool Match( CSIPClientTransaction& aTrans );
       
   158 
       
   159     /**
       
   160      * If the request matches with the transaction
       
   161      *
       
   162      * @since S60 3.2     
       
   163      * @param aType transaction type
       
   164      * @return ETrue if matches
       
   165      */
       
   166     TBool Match( TSimpleSipReqType aType ) const;
       
   167 
       
   168     /**
       
   169      * If the request matches with the transaction
       
   170      *
       
   171      * @since S60 3.2     
       
   172      * @param aDialog dialog
       
   173      * @return ETrue if matches
       
   174      */
       
   175     TBool Match( const CSIPDialog& aDialog ) const;
       
   176 
       
   177     /**
       
   178      * If the request matches with client request
       
   179      *
       
   180      * @since S60 3.2     
       
   181      * @param aReq client request
       
   182      * @return ETrue if matches
       
   183      */
       
   184     TBool Match( MSimpleEngineRequest& aReq ) const;
       
   185 
       
   186     /**
       
   187      * Complete the pending request
       
   188      *
       
   189      * @since S60 3.2     
       
   190      * @param aStatus response status
       
   191      */
       
   192     void Complete( TInt aStatus );
       
   193 
       
   194     /**
       
   195      * Complete event request
       
   196      *
       
   197      * @since S60 3.2
       
   198      */
       
   199     void CompleteEvent( );
       
   200 
       
   201     /**
       
   202      * Set refresh time for the SIP request
       
   203      *
       
   204      * @since S60 3.2   
       
   205      * @param aTime time in seconds       
       
   206      */
       
   207     void SetRefreshTime( TUint aTime );
       
   208 
       
   209     /**
       
   210      * Refresh time accessor
       
   211      *
       
   212      * @since S60 3.2     
       
   213      * @return refresh time in seconds
       
   214      */
       
   215     TUint RefreshTime () const;
       
   216 
       
   217     /**
       
   218      * Start refresh timer for this request based
       
   219      * on iRefreshTime.
       
   220      *
       
   221      * @since S60 3.2     
       
   222      * @param aTime special time, if iRefreshTime not used
       
   223      */
       
   224     void StartRefreshTimer( TUint aTime = 0 );
       
   225 
       
   226     /**
       
   227      * Stop refresh timer
       
   228      *
       
   229      * @since S60 3.2     
       
   230      */
       
   231     void StopRefreshTimer();
       
   232 
       
   233     /**
       
   234      * Start expiry timer for this request
       
   235      *
       
   236      * @since S60 3.2     
       
   237      * @param aTime time
       
   238      */
       
   239     void StartExpiryTimer( TUint aTime );
       
   240 
       
   241     /**
       
   242      * Stop expiry timer
       
   243      *
       
   244      * @since S60 3.2     
       
   245      */
       
   246     void StopExpiryTimer();
       
   247 
       
   248     /**
       
   249      * Counts retry time period
       
   250      *
       
   251      * @since S60 3.2     
       
   252      * @return time
       
   253      */
       
   254     TUint RetryTime();
       
   255 
       
   256     /**
       
   257      * Counts retry expiry time period
       
   258      *
       
   259      * @since S60 3.2     
       
   260      * @return time
       
   261      */
       
   262     TInt RetryExpiryTime();
       
   263 
       
   264     /**
       
   265      * Set SIP-ETag value
       
   266      *
       
   267      * @since S60 3.2     
       
   268      * @param aTag tag, OWNERSHIP IS TRANSFERRED.
       
   269      */
       
   270     void SetETag( HBufC8* aTag );
       
   271 
       
   272     /**
       
   273      * get SIP-ETag value
       
   274      *
       
   275      * @since S60 3.2     
       
   276      * @return SIP-ETag value.
       
   277      */
       
   278     TPtrC8 ETag() const;
       
   279 
       
   280     /**
       
   281      * Status getter
       
   282      *
       
   283      * @since S60 3.2     
       
   284      * @return status
       
   285      */
       
   286     TUint Status() const;
       
   287 
       
   288     /**
       
   289      * Status setter
       
   290      *
       
   291      * @since S60 3.2     
       
   292      * @param aVal status value
       
   293      */
       
   294     void SetStatus( TUint aVal );
       
   295 
       
   296     /**
       
   297      * Dialog setter
       
   298      *
       
   299      * @since S60 3.2     
       
   300      * @param aDialog dialog
       
   301      */
       
   302     void SetDialog( CSIPSubscribeDialogAssoc* aDialog );
       
   303 
       
   304     /**
       
   305      * Dialog getter
       
   306      *
       
   307      * @since S60 3.2     
       
   308      * @return dialog
       
   309      */
       
   310     CSIPSubscribeDialogAssoc* Dialog( );
       
   311 
       
   312     /**
       
   313      * State accessor
       
   314      *
       
   315      * @since S60 3.2     
       
   316      * @return state
       
   317      */
       
   318     TSimpleReqState ReqState() const;
       
   319 
       
   320     /**
       
   321      * State setter
       
   322      *
       
   323      * @since S60 3.2     
       
   324      * @param aState state
       
   325      */
       
   326     void SetReqState( TSimpleReqState aState );
       
   327 
       
   328     /**
       
   329      * SOURCE-THROTTLE-PUBLISH time setter
       
   330      * @param expiry time in seconds
       
   331      */
       
   332     void SetThrottleTime( TUint aSeconds );
       
   333 
       
   334     /**
       
   335      * SOURCE-THROTTLE-PUBLISH time getter
       
   336      *
       
   337      * @since S60 3.2     
       
   338      * @return expiry time
       
   339      */
       
   340     TTime ThrottleTime( );
       
   341 
       
   342     /**
       
   343      * Retry-After SIP header parameter value accessor
       
   344      *
       
   345      * @since S60 3.2     
       
   346      * @return Retry-After SIP header parameter, 0 if not present
       
   347      */
       
   348     TUint RetryAfter();
       
   349 
       
   350     /**
       
   351      * Retry-After SIP header parameter value setter
       
   352      *
       
   353      * @since S60 3.2     
       
   354      * @param aVal Retry-After SIP header parameter, 0 if not present
       
   355      */
       
   356     void SetRetryAfter( TUint aVal );
       
   357 
       
   358     /**
       
   359      * Original error reason setter
       
   360      *
       
   361      * @since S60 3.2     
       
   362      * @param aVal error code
       
   363      */
       
   364     void SetReason( TInt aVal );
       
   365 
       
   366     /**
       
   367      * Original error reason getter
       
   368      *
       
   369      * @since S60 3.2     
       
   370      * @param aVal error code
       
   371      */
       
   372     TInt Reason( );
       
   373 
       
   374     /**
       
   375      * Error notify counter increse
       
   376      *
       
   377      * @since S60 3.2     
       
   378      */
       
   379     void PlusErrCount( );
       
   380 
       
   381     /**
       
   382      * Error notify reset
       
   383      *
       
   384      * @since S60 3.2     
       
   385      */
       
   386     void ResetErrCount( );
       
   387 
       
   388     /**
       
   389      * Error notify getter
       
   390      *
       
   391      * @since S60 3.2     
       
   392      */
       
   393     TInt ErrCount( );
       
   394 
       
   395     /**
       
   396      * Pending accessor
       
   397      *
       
   398      * @since S60 3.2     
       
   399      * return pending substate
       
   400      */
       
   401     TSimplePendingSubState PendingState();
       
   402 
       
   403     /**
       
   404      * Pending state setter
       
   405      *
       
   406      * @since S60 3.2     
       
   407      * @param aVal state
       
   408      */
       
   409     void SetPendingState( TSimplePendingSubState aVal );
       
   410     
       
   411     /**
       
   412      * Add new Pending state to the current state
       
   413      *
       
   414      * @since S60 3.2     
       
   415      * @param aVal state
       
   416      */
       
   417     void AddPendingState( TSimplePendingSubState aVal );    
       
   418 
       
   419     /**
       
   420      * Access iData
       
   421      *
       
   422      * @since S60 3.2     
       
   423      * @return data
       
   424      */
       
   425     TPtrC8 Data() const;
       
   426 
       
   427     /**
       
   428      * Set iData
       
   429      *
       
   430      * @since S60 3.2     
       
   431      * @param aData data
       
   432      */
       
   433     void SetDataL( const TDesC8& aData );
       
   434     
       
   435     /**
       
   436      * Access iRecipientId
       
   437      *
       
   438      * @since S60 5.0
       
   439      * @return recipient ID
       
   440      */
       
   441     TPtrC8 RecipientL() const;
       
   442 
       
   443     /**
       
   444      * Set iRecipientId
       
   445      *
       
   446      * @since S60 5.0
       
   447      * @param aRecipientId recipient ID
       
   448      */
       
   449     void SetRecipientL( const TDesC8& aRecipientId );
       
   450 
       
   451     /**
       
   452      * Accesor for iGivenETag
       
   453      * 
       
   454      * @since S60 3.2       
       
   455      * @return true if given ETag
       
   456      */
       
   457     TBool GivenETag() const; 
       
   458      
       
   459     /**
       
   460      * Setter for iGivenETag
       
   461      * 
       
   462      * @since S60 3.2       
       
   463      * @param aVal true if given ETag
       
   464      */  
       
   465     void SetGivenETag( TBool aVal );         
       
   466     
       
   467     /**
       
   468      * Accesor for request MIME content type
       
   469      * 
       
   470      * @since S60 3.2       
       
   471      * @return content type
       
   472      */
       
   473     TPtrC8 RequestContentType();
       
   474 
       
   475     /**
       
   476      * Setter for request MIME content type
       
   477      *
       
   478      * @since S60 3.2       
       
   479      * @param aData content type
       
   480      */     
       
   481      
       
   482     void SetRequestContentTypeL( const TDesC8& aData );
       
   483     
       
   484     /**
       
   485      * Get SIP Subscription-State.
       
   486      * @return Subscription-State
       
   487      */
       
   488     MSimpleEngineRequest::TSimpleSipSubscriptionState SipSubscriptionState();
       
   489     
       
   490 
       
   491 private:
       
   492 
       
   493     /**
       
   494      * contructor
       
   495      */
       
   496     CSimpleRequest( MSimpleSipConnCallback& aEngine,
       
   497                     MSimpleEngineRequest& aReq,
       
   498                     TSimpleSipReqType aType,
       
   499                     TUint aExpires );
       
   500 
       
   501     /**
       
   502      * contructor
       
   503      */
       
   504     void ConstructL();
       
   505 
       
   506     /**
       
   507      * Keep destructor private since it's easier to
       
   508      * find Destroy() methods in the code when
       
   509      * debugging.
       
   510      *
       
   511      * @since S60 3.2     
       
   512      */
       
   513     virtual ~CSimpleRequest();
       
   514 
       
   515     /**
       
   516      * Handle state machine of subscription
       
   517      *
       
   518      * @since S60 3.2     
       
   519      * @param aStatus status
       
   520      */
       
   521     void DoCompleteSubscription( TInt aStatus );
       
   522 
       
   523     /**
       
   524      * Handle notification of subscription and update state machine if terminated.
       
   525      *
       
   526      * @since S60 3.2     
       
   527      * @param aStatus status
       
   528      */
       
   529     void DoCompleteNotification( TInt aStatus );
       
   530 
       
   531     /**
       
   532      * Handle state machine of publication
       
   533      *
       
   534      * @since S60 3.2     
       
   535      * @param aStatus status
       
   536      */
       
   537     void DoCompletePublication( TInt aStatus );
       
   538 
       
   539 
       
   540 private: // data
       
   541 
       
   542     TDblQueLink iLink;
       
   543     
       
   544     /**
       
   545      * Client callback observer
       
   546      */
       
   547     MSimpleSipConnCallback& iEngine;
       
   548 
       
   549     /**
       
   550      * Client request
       
   551      */
       
   552     MSimpleEngineRequest& iReq;
       
   553 
       
   554     /**
       
   555      * SIP client transaction
       
   556      * Own,
       
   557      */
       
   558     CSIPClientTransaction* iTrans;
       
   559 
       
   560     /**
       
   561      * SIP refresher
       
   562      * Own.
       
   563      */
       
   564     CSIPRefresh* iSipRefresh;
       
   565 
       
   566     /**
       
   567      * Request type
       
   568      */
       
   569     TSimpleSipReqType iType;
       
   570 
       
   571     /**
       
   572      * Current Refresh period
       
   573      */
       
   574     TUint iRefreshTime;
       
   575 
       
   576     /**
       
   577      * Request expiry time in IF
       
   578      */
       
   579     TUint iExpirationTime;
       
   580 
       
   581     /**
       
   582      * Refresh timer.
       
   583      * Own.
       
   584      */
       
   585     CSimpleRefreshTimer* iRefreshTimer;
       
   586 
       
   587     /**
       
   588      * Refresh timer.
       
   589      * Own.
       
   590      */
       
   591     CSimpleExpiryTimer* iExpiryTimer;
       
   592 
       
   593     /**
       
   594      * ETag.
       
   595      * Own.
       
   596      */
       
   597     HBufC8* iETag;
       
   598 
       
   599     /**
       
   600      * Subscribe dialog
       
   601      * Own.
       
   602      */
       
   603     CSIPSubscribeDialogAssoc* iDialog;
       
   604 
       
   605     /**
       
   606      * SIP status (response)
       
   607      */
       
   608     TUint iStatus;
       
   609 
       
   610     /**
       
   611      * Current request state
       
   612      */
       
   613     TSimpleReqState iState;
       
   614 
       
   615     /**
       
   616      * The expiry time of SOURCE-THROTTLE-PUBLISH
       
   617      */
       
   618     TTime iThrottleTime;
       
   619 
       
   620     /**
       
   621      * SIP header retry-after parameter
       
   622      */
       
   623     TUint iRetryAfter;
       
   624 
       
   625     /**
       
   626      * Reason code
       
   627      */
       
   628     TInt iReason;
       
   629 
       
   630     /**
       
   631      * Error notify counter
       
   632      */
       
   633     TInt iErrNotify;
       
   634 
       
   635     /**
       
   636      * Expires
       
   637      */
       
   638     TUint iExpires;
       
   639 
       
   640     /**
       
   641      * Pending request state
       
   642      */
       
   643     TSimplePendingSubState iPendingState;
       
   644 
       
   645     /**
       
   646      * Request data
       
   647      * Own.
       
   648      */
       
   649     HBufC8* iData;
       
   650     
       
   651     /**
       
   652      * IM message recipient ID
       
   653      * Own.
       
   654      */
       
   655     HBufC8* iRecipientId;
       
   656 
       
   657     /**
       
   658      * Request Content type
       
   659      * Own.
       
   660      */
       
   661     HBufC8* iRequestContentType; 
       
   662     
       
   663     /**
       
   664      * If publish stoppig uses given ETag
       
   665      */
       
   666     TBool iGivenETag;
       
   667     
       
   668     /**
       
   669      * SIP Subscription-State
       
   670      */
       
   671     MSimpleEngineRequest::TSimpleSipSubscriptionState iSubscriptionState;
       
   672     
       
   673     /**
       
   674      * response counter for subscription stop (unsubscribe)
       
   675      */
       
   676     TInt iRespCount;    
       
   677 
       
   678 #ifdef _DEBUG
       
   679     friend class T_CSimpleRequest;
       
   680     friend class T_CSimpleSipConnectionObserver;
       
   681     friend class CSimpleSipConnCallbackStub;
       
   682 #endif
       
   683 };
       
   684 
       
   685     TInt CSimpleRequest::LinkOffset()
       
   686         {
       
   687         return _FOFF(CSimpleRequest, iLink);
       
   688         }  
       
   689 
       
   690 #endif
       
   691 
       
   692 // End of File