mmsharing/livecommsui/lcui/tsrc/mustester/Stubs/sipclientstub/inc/sipconnection.h
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
child 35 6c57ef9392d2
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
     1 /*
       
     2 * Copyright (c) 2003 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 #ifndef CSIPCONNECTION_H
       
    20 #define CSIPCONNECTION_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <in_sock.h>
       
    25 
       
    26 // FORWARD DECLARATIONS
       
    27 class CSIP;
       
    28 class MSIPConnectionObserver;
       
    29 class CSIPTransactionBase;
       
    30 class CSIPClientTransaction;
       
    31 class CSIPServerTransaction;
       
    32 class MSIPRegistrationContext;
       
    33 class CSIPRegistrationBinding;
       
    34 class CRegistrationState;
       
    35 class CSIPDialog;
       
    36 class CDialogState;
       
    37 class CSIPRefresh;
       
    38 class CSIPMessageElements;
       
    39 class CSIPRequestElements;
       
    40 class CSIPResponseElements;
       
    41 class CSIPClientConnectionObserver;
       
    42 class CConnectionCallback;
       
    43 class CSIPClientConnection;
       
    44 
       
    45 
       
    46 //CONSTANTS
       
    47 /** SIP minimum value for the expiration in seconds*/
       
    48 //const TUint KSIPMinExpirationValue=60;
       
    49 
       
    50 
       
    51 // CLASS DECLARATION
       
    52 
       
    53 /**
       
    54 *  Class for monitoring connection's state and sending SIP requests outside
       
    55 *  the dialog associations.Class must not be used
       
    56 *  -for sending requests to which received non-failure response creates a dialog
       
    57 *  -for sending requests that must be sent within SIP dialog
       
    58 * Note that the user can have only one instance of the class per same IAP-id
       
    59 */
       
    60 class CSIPConnection :
       
    61     public CBase
       
    62 	{
       
    63     public:
       
    64     
       
    65         /** Connection states */
       
    66         enum TState 
       
    67             {
       
    68             /** Connection initializing */
       
    69 			EInit=1,
       
    70 			/** Connection active */
       
    71 			EActive,
       
    72 			/** Connection suspended */
       
    73 			ESuspended,
       
    74 			/** Connection is inactive */
       
    75 			EInactive,
       
    76 			/** Connection is permanently unavailable */
       
    77 			EUnavailable
       
    78             };
       
    79 
       
    80     public:  // Constructors and destructor
       
    81 
       
    82 	    /**
       
    83         * Two-phased constructor.
       
    84 		* @param aSip a handle to the SIP server
       
    85 		* @param aIapId IAP-id
       
    86 		* @param aObserver a observer for receiving asynchonous events on this
       
    87         *   connection
       
    88         * @return New object, ownership is transferred
       
    89         */
       
    90 
       
    91 		IMPORT_C static CSIPConnection*
       
    92             NewL(CSIP& aSIP,
       
    93 				 TUint32 aIapId,
       
    94 				 MSIPConnectionObserver& aObserver);
       
    95 
       
    96 
       
    97 	    /**
       
    98         * Two-phased constructor.
       
    99 		* Constructs an object and adds the pointer to the cleanup stack;
       
   100 		* @param aSip a handle to the SIP server
       
   101 		* @param aIapId IAP-id
       
   102 		* @param aObserver a observer for receiving asynchonous events on this
       
   103         *   connection
       
   104         * @return New object, ownership is transferred
       
   105         */
       
   106 
       
   107 		IMPORT_C static CSIPConnection*
       
   108             NewLC(CSIP& aSIP,
       
   109 				  TUint32 aIapId,
       
   110 				  MSIPConnectionObserver& aObserver);
       
   111 
       
   112 
       
   113 		/**
       
   114 		* Destructor
       
   115 		*/
       
   116 
       
   117 		IMPORT_C ~CSIPConnection();
       
   118 
       
   119     public: // New functions
       
   120 
       
   121         /**
       
   122 		* Gets current state of the connection        
       
   123         * @return current state of the connection
       
   124         */
       
   125 
       
   126 		IMPORT_C TState State() const;
       
   127 
       
   128         /**
       
   129 		* Creates SIP request and sends it to the given destination.
       
   130 		* The function must not be used with SIP requests that creates
       
   131 		* SIP dialog associations or must be sent within SIP dialog
       
   132 		* association.
       
   133 		* This provokes the Non-invite state machine.
       
   134 		* This function must be used if the user has created the
       
   135 		* registration binding.
       
   136 		* @pre State() == EActive.
       
   137 		* @pre aContext.IsContextActive()==ETrue
       
   138 		* @param aElements contains local and remote addresses,
       
   139 		*		 optional SIP message headers and body.
       
   140 		*        The ownership is transferred.
       
   141 		* @param aContext defines outbound proxy to be used. If the user
       
   142 		*        does not provide from-address it will be constucted using
       
   143 		*        user's AOR used during the registration.
       
   144         * @return SIP client transaction, ownership is transferred
       
   145         */
       
   146 
       
   147 		IMPORT_C CSIPClientTransaction*
       
   148             SendRequestL(CSIPRequestElements* aElements,
       
   149                          const MSIPRegistrationContext& aContext);
       
   150 
       
   151 
       
   152         /**
       
   153 		* Creates SIP request and sends it to the given destination.
       
   154 		* The function must not be used with SIP request that creates
       
   155 		* SIP dialog associations or must be sent within SIP diallog
       
   156 		* association.
       
   157 		* This provokes the Non-invite state machine.
       
   158 		* This function must be used if the user has created the
       
   159 		* registration binding.
       
   160 		* @pre State() == EActive.
       
   161 		* @pre aContext.IsContextActive()==ETrue
       
   162 		* @param aElements contains local and remote addresses,
       
   163 		*		 optional SIP message headers and body.
       
   164 		*        The ownership is transferred.
       
   165 		* @param aContext defines outbound proxy to be used. If the user
       
   166 		*        does not provide from-address it will 
       
   167 		*        be constucted using user's AOR used during the registration.
       
   168 		* @param aRefresh defines the refresh interval for this transaction.
       
   169         * @return SIP client transaction, ownership is transferred
       
   170         */
       
   171 
       
   172 		IMPORT_C CSIPClientTransaction*
       
   173             SendRequestL(CSIPRequestElements* aElements,                                        
       
   174                          const MSIPRegistrationContext& aContext,
       
   175 						 CSIPRefresh& aRefresh); 
       
   176 
       
   177 
       
   178         /**
       
   179 		* Creates SIP request and sends it to the given destination.
       
   180 		* The function must not be used with SIP request that creates SIP
       
   181 		* diallog associations or must be sent within SIP dialog association.
       
   182 		* This invokes the Non-invite state machine.
       
   183 		* @pre State() == EActive.
       
   184 		* @pre aElements.FromHeader() != 0
       
   185 		* @param aElements contains local and remote addresses,
       
   186 		*		 optional SIP message headers and body.
       
   187 		*        The ownership is transferred.
       
   188         * @return SIP client transaction, ownership is transferred
       
   189         */
       
   190 
       
   191 		IMPORT_C CSIPClientTransaction*
       
   192             SendRequestL(CSIPRequestElements* aElements);
       
   193         
       
   194 
       
   195         /**
       
   196 		* Creates SIP request and sends it to the given destination.
       
   197 		* The function must not be used with SIP request that creates SIP
       
   198 		* dialog associations or must be sent within SIP dialog association.
       
   199 		* This invokes the Non-invite state machine.
       
   200 		* @pre State() == EActive.
       
   201 		* @pre aElements.FromHeader() != 0
       
   202 		* @param aElements contains local and remote addresses,
       
   203 		*		 optional SIP message headers and body.
       
   204 		*        The ownership is transferred.
       
   205 		* @param aRefresh indicates that transaction will be refreshed
       
   206         * @return SIP client transaction, ownership is transferred
       
   207         */
       
   208 
       
   209 		IMPORT_C CSIPClientTransaction*
       
   210             SendRequestL(CSIPRequestElements* aElements,
       
   211 						 CSIPRefresh& aRefresh);
       
   212 
       
   213 
       
   214         /**
       
   215 		* Creates SIP REGISTER request and sends it to the given destination.
       
   216 		* User must no define any Contact or Expires-headers
       
   217 		* in the provided elements.
       
   218 		* @pre State() == EActive
       
   219         * @pre aElements != 0
       
   220 		* @pre aElements->Method().DesC().Length()==0
       
   221 		* @param aElements contains local and remote addresses, optional SIP
       
   222         *        message headers and body. User must not set any expires values
       
   223         *        to aElements. The ownership is transferred.
       
   224         * @return SIP REGISTER client transaction, ownership is transferred
       
   225         */
       
   226 
       
   227 		IMPORT_C CSIPClientTransaction*
       
   228             FetchRegistrationsL(CSIPRequestElements* aElements);
       
   229             
       
   230         // Not in real SIP API:
       
   231         IMPORT_C void SetState(TState aState);    
       
   232 
       
   233 		//TODO:SHOULD THIS NEW FUNCTION BE INCLUDED INTO STUB???
       
   234 		/**
       
   235 		* Gets Iap-id used for this connection
       
   236 		* @return Iap-id
       
   237 		*/
       
   238 		
       
   239 		IMPORT_C TUint32 IapId() const;
       
   240 		
       
   241 		
       
   242 		/**
       
   243         * Gets SIP server handle
       
   244         * @return handle to SIP server, or 0-pointer if SIP server does not
       
   245         *	exist any more
       
   246         */
       
   247         IMPORT_C CSIP* SIP();
       
   248   
       
   249 		/**
       
   250         * Gets SIP server handle
       
   251         * @return handle to SIP server, or 0-pointer if SIP server does not
       
   252         *	exist any more
       
   253         */
       
   254         
       
   255         IMPORT_C const CSIP* SIP() const;
       
   256 		//TODO:ENDS
       
   257 		
       
   258         /**
       
   259 		* Incoming request outside dialog has been received.
       
   260 		*
       
   261 		* @param aTransaction Server transaction. Ownership is transferred.        
       
   262         */
       
   263 
       
   264         void IncomingRequestL(CSIPServerTransaction* aTransaction) const;
       
   265 
       
   266         /**
       
   267         * Gets the local IP address of this CSIPConnection 
       
   268         * that is used by the SIP implementation.
       
   269         * The user should re-new the call whenever the connection state changes
       
   270         * to the CSIPConnection::EActive in order to verify the correctness of
       
   271         * the previously retrieved local IP address. The local IP address might
       
   272         * be different as a result of the connection state change.
       
   273         * @pre State() == CSIPConnection::EActive
       
   274         * @param aAddr on return filled with local IP address
       
   275         * @leave a system-wide error code
       
   276         */ 	                         
       
   277 	    IMPORT_C void GetLocalAddrL(TInetAddr& aAddr) const;
       
   278 
       
   279         
       
   280         /**
       
   281 		* Incoming request within dialog has been received.
       
   282 		*
       
   283 		* @param aTransaction Server transaction. Ownership is transferred.
       
   284         * @param aDialogId Identifies the dialog to which the transaction
       
   285         *   belongs to.
       
   286         */
       
   287 
       
   288         void IncomingDialogRequestL(CSIPServerTransaction* aTransaction,
       
   289                               		TUint32 aDialogId);
       
   290 
       
   291         void IncomingResponseL(CSIPResponseElements* aElements,
       
   292                                TUint32 aRequestId) const;
       
   293     
       
   294         void IncomingRegistrationResponseL(CSIPResponseElements* aElements,
       
   295 		                       			   TUint32 aRequestId,
       
   296 					           			   TUint32 aRegistrationId) const;
       
   297 
       
   298         void IncomingRefreshResponseL(CSIPResponseElements* aElements,
       
   299 		                       		  TUint32 aRequestId,
       
   300 							   		  TUint32 aRefreshId);
       
   301 
       
   302 
       
   303         void ErrorOccured(TInt aError, TUint32 aRequestId) const;
       
   304 
       
   305         void RefreshErrorOccured(TInt aError, TUint32 aRefreshId) const;
       
   306 
       
   307 	    void RegistrationErrorOccured(TInt aError,
       
   308                           			  TUint32 aRegistrationId,
       
   309                           			  TUint32 aRequestId) const;
       
   310 
       
   311 		void DialogErrorOccured(TInt aError,
       
   312                           		TUint32 aDialogId,
       
   313                           		TUint32 aRequestId) const;
       
   314 
       
   315         void DialogErrorOccured(TInt aError,
       
   316                           		TUint32 aDialogId,
       
   317                           		TUint32 aRefreshId,
       
   318                           		TUint32 aRequestId) const;
       
   319 
       
   320         void ConnectionStateChanged(CSIPConnection::TState aState);
       
   321 
       
   322         void InviteCompleted(TUint32 aRequestId) const;
       
   323 
       
   324 
       
   325 		/**
       
   326         * Searches for a transaction with the matching aRequestId.
       
   327 		* @param aRequestId RequestId associated with the transaction
       
   328 		* @return Found transaction or NULL if not found. Ownership is not
       
   329         *   transferred.
       
   330         */
       
   331         
       
   332         CSIPTransactionBase* FindTransaction(TUint32 aRequestId) const;
       
   333    
       
   334    
       
   335         TInt AddRegistration(CSIPRegistrationBinding* aRegistration);
       
   336         void RemoveRegistration(const CSIPRegistrationBinding* aRegistration);
       
   337         
       
   338 
       
   339       /**
       
   340         * Searches for a registration binding, using aRegistrationId and
       
   341         * aRequestId as keys. Registration might not yet have received
       
   342         * RegistrationId from SIP client, so the aRequestId may be needed to
       
   343         * locate the registration binding.
       
   344         * @param aRegistrationId RegistrationId of the registration binding
       
   345 		* @param aRequestId RequestId of a transaction associated with the
       
   346         *   registration
       
   347 		* @return Found registration binding or NULL if not found.
       
   348 		*	Ownership is not transferred.
       
   349         */
       
   350         
       
   351         CSIPRegistrationBinding* FindRegistration(TUint32 aRegistrationId,
       
   352                              			   		  TUint32 aRequestId) const;
       
   353 
       
   354 
       
   355         TInt AddDialog(CSIPDialog* aDialog);
       
   356         void RemoveDialog(const CSIPDialog* aDialog);
       
   357 
       
   358 
       
   359         /**
       
   360         * Searches for a dialog, using aRequestId as a key.
       
   361         * @param aRequestId RequestId of a transaction associated with the
       
   362         *   dialog
       
   363 		* @return Found dialog or NULL if not found. Ownership is not
       
   364         *   transferred.
       
   365         */
       
   366 
       
   367         CSIPDialog* FindDialogByRequestId(TUint32 aRequestId) const;
       
   368 
       
   369 
       
   370         /**
       
   371 		* Informs CSIPConnection that the associated CSIP instance has been
       
   372         * deleted. After this the CSIPConnection object can't be used anymore.
       
   373 		*/
       
   374 
       
   375         void CSIPDeleted();
       
   376 
       
   377 
       
   378         /**
       
   379 		* Obtains the initial state for registration state machine.
       
   380         *
       
   381         * @return Initial registration state, ownership is not transferred
       
   382 		*/
       
   383 
       
   384         CRegistrationState* InitialRegisterStateL() const;
       
   385 
       
   386 
       
   387         /**
       
   388 		* Obtains the initial state for dialog state machine.
       
   389         *
       
   390         * @return Initial dialog state, ownership is not transferred
       
   391 		*/
       
   392 
       
   393         CDialogState* InitialDialogStateL() const;
       
   394 
       
   395 
       
   396         /**
       
   397         * Response related to a dialog has been received.
       
   398 		*
       
   399         * @param aElements SIP response elements. Ownership is transferred.
       
   400         * @param aRequestId Identifies the transaction
       
   401         * @param aDialogId DialogId
       
   402         * @param aRefreshId NULL if the response is not related to a refresh,
       
   403         *   otherwise the RefreshId. Ownership is not transferred.
       
   404 		*/
       
   405 
       
   406         void IncomingResponseToDialogL(CSIPResponseElements* aElements,
       
   407 		                               TUint32 aRequestId,
       
   408                                        TUint32 aDialogId,
       
   409                                        TUint32* aRefreshId);
       
   410 
       
   411     private:
       
   412         CSIPConnection(CSIP& aSIP,
       
   413                        TUint32 aIapId,
       
   414                        MSIPConnectionObserver& aObserver);
       
   415 
       
   416         void ConstructL();
       
   417 
       
   418 
       
   419         /**
       
   420         * Send a SIP request.
       
   421         *
       
   422 		* @param aElements SIP headers. Ownership is transferred.
       
   423         * @param aRegistrationId If non-NULL, request will use the outbound
       
   424         *   proxy and some SIP headers from the registration identified by
       
   425         *   aRegistrationId. Ownership is not transferred.
       
   426         * @param aRefresh If non-NULL, the request will be refreshed. Otherwise
       
   427         *   NULL. Ownership is not transferred.
       
   428 		* @return New transaction. Ownership is transferred.
       
   429         */
       
   430 
       
   431         CSIPClientTransaction*
       
   432             SendRequestL(CSIPRequestElements* aElements,
       
   433                          TUint32* aRegistrationId,
       
   434 						 CSIPRefresh* aRefresh);
       
   435 
       
   436 
       
   437         /**
       
   438         * Searches for a refresh and transaction, using aRequestId and
       
   439         * aRefreshId as keys.        
       
   440 		* @param aRequestId RequestId associated with the refreshed transaction
       
   441         * @param aRefreshId RefreshId associated with the refresh instance
       
   442         * @param aRefresh OUT: if refresh was found, this pointer is set to the
       
   443         *   refresh instance. Ownership is not transferred.
       
   444         * @param aTransaction OUT: if transaction was found, this pointer is
       
   445         *   set to the refreshed client transaction. Ownership is not
       
   446         *   transferred.
       
   447 		* @return ETrue if found, EFalse otherwise
       
   448         */
       
   449 
       
   450         TBool FindRefresh(TUint32 aRequestId,
       
   451                           TUint32 aRefreshId,
       
   452                           CSIPRefresh** aRefresh,
       
   453                           CSIPClientTransaction** aTransaction) const;
       
   454 
       
   455         /**
       
   456         * Searches for a registration binding, using aRequestId as a key.
       
   457 		* @param aRequestId RequestId of a transaction associated with the
       
   458         *   registration binding
       
   459 		* @return Found registration binding or NULL if not found.
       
   460 		*	Ownership is not transferred.
       
   461         */
       
   462 
       
   463         CSIPRegistrationBinding* FindRegistration(TUint32 aRequestId) const;
       
   464 
       
   465         
       
   466         /**
       
   467         * Searches for a dialog, using aDialogId as a key.        
       
   468         * @param aDialogId DialogId of the dialog.
       
   469 		* @return Found dialog or NULL if not found. Ownership is not
       
   470         *   transferred.
       
   471         */
       
   472 
       
   473         CSIPDialog* FindDialog(TUint32 aDialogId) const;
       
   474 
       
   475 
       
   476         /**
       
   477         * A request has been received with a dialogId, but no matching dialog
       
   478         * exists.
       
   479 		* If the request is NOTIFY, it is stored until a response with the same
       
   480         * dialogId is received. Then the response is passed to dialog and after
       
   481         * that all the stored NOTIFY are passed to the same dialog.
       
   482         * This is needed since NOTIFY can be received before a sent SUBSCRIBE
       
   483         * receives a response with dialogId.
       
   484 		*
       
   485         * @param aTransaction Server transaction, ownership is transferred
       
   486         * @param aDialogId DialogId
       
   487 		*/
       
   488 
       
   489         void IncomingRequestBeforeDialogExistsL(
       
   490                                     CSIPServerTransaction* aTransaction,
       
   491                                     TUint32 aDialogId);
       
   492 
       
   493 
       
   494         /**
       
   495 		* Extracts the oldest stored transaction for the dialog identified by
       
   496         * aDialogId.
       
   497         * @param aDialogId DialogId
       
   498         * @return Server transaction or NULL if no transaction is stored for
       
   499         *   the dialog. Ownership is transferred.
       
   500 		*/
       
   501 
       
   502         CSIPServerTransaction* GetStoredTransaction(TUint32 aDialogId);
       
   503 
       
   504 
       
   505         /**
       
   506 		* Checks that CSIP is available for use (not NULL). If iSIP is NULL,
       
   507         * it means user has deleted a resource needed by CSIPConnection, and
       
   508         * this function leaves.
       
   509 		*/
       
   510 
       
   511         void CheckCSipL() const;       
       
   512 
       
   513 
       
   514         /**
       
   515 		* Connection is no longer available. All registrations, dialogs,
       
   516         * transactions and refreshes using this connection are terminated, but
       
   517         * not deleted.
       
   518 		*/
       
   519 
       
   520         void ConnectionLost();
       
   521 
       
   522 
       
   523         //The used CSIP instance. CSIPConnection doesn't own the CSIP.
       
   524         //If this pointer is NULL; it means application has deleted the
       
   525         //CSIP instance before deleting the CSIPConnection, and this
       
   526         //CSIPConnection is now useless.
       
   527         CSIP* iSIP;
       
   528 
       
   529         //IAP-id of this connection
       
   530         TUint32 iIapId;
       
   531 
       
   532         //Callback to upper layer
       
   533         MSIPConnectionObserver& iObserver;
       
   534 
       
   535         //Callback receiving events from client
       
   536         CSIPClientConnectionObserver* iClientConnectionObserver;        
       
   537 
       
   538         //Connection used by this CSIPConnection instance
       
   539         CSIPClientConnection* iClientConnection;
       
   540 
       
   541         //CSIPConnection doesn't own CSIPRegistrationBindings
       
   542         RPointerArray<CSIPRegistrationBinding> iRegistrations;
       
   543 
       
   544         //CSIPConnection doesn't delete the CSIPDialog objects. CSIPDialog
       
   545         //deletes itself when its last dialog association is deleted.
       
   546         //NOTE: When CSIPDialog has just been created and has no dialog
       
   547         //associations yet, it must be stored in CleanupStack, otherwise it
       
   548         //won't be freed if leave occurs!
       
   549         RPointerArray<CSIPDialog> iDialogs;
       
   550 
       
   551         //CSIPConnection has to know which transactions are attached to it, but
       
   552         //it doesn't own the transactions. Transaction's ownership is passed
       
   553         //to application.
       
   554         RPointerArray<CSIPTransactionBase> iTransactions;
       
   555 
       
   556         //Standalone refreshes, application owns these
       
   557         RPointerArray<CSIPRefresh> iRefreshes;
       
   558 
       
   559         //To avoid using callbacks to MSIPConnectionObserver from within
       
   560         //CSIPRegistrationBinding and CSIPDialog, CConnectionCallback is passed to
       
   561         //the methods which would need to use MSIPConnectionObserver calls.
       
   562         //CSIPRegistrationBinding and CSIPDialog will fill CConnectionCallback with
       
   563         //the selected callback method and its parameters, and by returning
       
   564         //ETrue they tell to CSIPConnection that a callback has to be done.
       
   565         CConnectionCallback* iCallbackInfo;
       
   566         
       
   567         
       
   568         // Not in real SIP API
       
   569         TState iState;
       
   570 	};
       
   571 
       
   572 #endif
       
   573