S60 3rd Edition SDK for Symbian OS
Example Applications Guide

SIPExSIPEngine.h

00001 /*
00002 * ==============================================================================
00003 *  Name        : SIPExSIPEngine.h
00004 *  Part of     : SIPExSIPEngineSIPEngine
00005 *  Interface   : 
00006 *  Description : 
00007 *  Version     : 
00008 *
00009 *  Copyright (c) 2004-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */    
00015 
00016 #ifndef _SIPEXSIPENGINE_H_
00017 #define _SIPEXSIPENGINE_H_
00018 
00019 // INCLUDES
00020 #include <e32base.h>
00021 #include <e32std.h>
00022 #include <e32math.h>
00023 #include <s32mem.h>
00024 #include <in_sock.h>
00025 
00026 #include <sip.h>
00027 #include <sipdialog.h>
00028 #include <sipobserver.h>
00029 #include <sipinvitedialogassoc.h>
00030 #include <sipconnectionobserver.h>
00031 #include <sipservertransaction.h>
00032 #include <sipmessageelements.h>
00033 #include <siprequestelements.h>
00034 
00035 #include <sdpdocument.h>
00036 #include <sdpmediafield.h>
00037 #include <sdporiginfield.h>
00038 #include <sdpconnectionfield.h>
00039 #include <sdpcodecstringconstants.h>
00040 #include <sdpcodecstringpool.h>
00041 
00042 #include <sipprofile.h>
00043 #include <sipprofileregistry.h>
00044 #include <sipprofileregistryobserver.h>
00045 
00046 #include <sipaddress.h>
00047 #include <sipcontenttypeheader.h>
00048 #include <sipfromheader.h>
00049 
00050 #include "SIPExSIPEngineObserver.h"
00051 
00052 #include "SIPExSIPIdleState.h"
00053 #include "SIPExSIPClientEstablishingState.h"
00054 #include "SIPExSIPClientOfferingState.h"
00055 #include "SIPExSIPServerOfferingState.h"
00056 #include "SIPExSIPServerEstablishingState.h"
00057 #include "SIPExSIPEstablishedState.h"
00058 #include "SIPExSIPTerminatingState.h"
00059 
00060 
00061 // FORWARD DECLARATIONS
00062 class CSIP;
00063 class CSIPDialog;
00064 class CSIPServerTransaction;
00065 class CSIPMessageElements;
00066 class CSIPRequestElements;
00067 
00068 class CSIPAddress;
00069 class CSIPContentTypeHeader;
00070 class CSIPFromHeader;
00071 
00072 class MSIPExSIPEngineObserver;
00073 
00074 class CSIPExSIPIdleState;
00075 class CSIPExSIPClientEstablishingState;
00076 class CSIPExSIPClientOfferingState;
00077 class CSIPExSIPServerOfferingState;
00078 class CSIPExSIPServerEstablishingState;
00079 class CSIPExSIPEstablishedState;
00080 class CSIPExSIPTerminatingState;
00081 
00082 
00083 // CLASS DECLARATION
00084 
00085 /**
00086 * CSIPExSIPEngine
00087 * Class for implementing the SIP Engine for the SIP
00088 * Example Application. The Engine provides API functions
00089 * for other parts of the Application, and maintains an
00090 * internal state machine to handle the SIP session.
00091 */
00092 class CSIPExSIPEngine: public CBase,
00093                                                            MSIPObserver,
00094                                                            MSIPConnectionObserver,
00095                                                            MSIPProfileRegistryObserver
00096         {
00097 
00098     public: // Constructors and destructor
00099 
00100                 /**
00101                 * NewL
00102                 * Create new instance of SIP Engine.
00103                 * @param aAppUid Application uid.
00104                 * @param aObserver Pointer to the Engine Observer.
00105                 * @return Pointer to new SIP Engine instance.
00106                 */
00107                 IMPORT_C static CSIPExSIPEngine* NewL( TUid aAppUid,
00108                                                                                                 MSIPExSIPEngineObserver* aObserver );
00109                 
00110                 /**
00111                 * Destructor.
00112                 */
00113                 virtual ~CSIPExSIPEngine();
00114                 
00115         private:
00116         
00117                 /**
00118                 * C++ default constructor.
00119                 */
00120                 CSIPExSIPEngine();
00121                 
00122                 /**
00123                 * 2nd phase construction.
00124                 * @param aAppUid Application uid.
00125                 * @param aObserver Pointer to the Engine Observer.
00126                 */
00127                 void ConstructL( TUid aAppUid,
00128                                                  MSIPExSIPEngineObserver* aObserver );
00129                 
00130         public: // New functions - services provided by the SIP Engine
00131 
00132                 /**
00133                 * EnableProfileL
00134                 * Enable the default profile.
00135                 * Callback is notified when operation is complete.
00136                 * Leaves if default SIP profile is not found or profile type is not expected.
00137                 * Returns true if profile was registered immediately after enabling.
00138                 */
00139                 IMPORT_C TBool EnableProfileL();
00140                 
00141                 /**
00142                 * DisableProfile
00143                 * Disable the current profile.
00144                 * Callback is notified when operation is complete.
00145                 */
00146                 IMPORT_C void DisableProfileL();
00147                 
00148                 
00149                 /**
00150                 * SendInvite
00151                 * Create and send an INVITE to the recipient
00152                 * identified by the parameter.
00153                 * @param aSipUri Address of the recipient.
00154                 */
00155                 IMPORT_C void SendInviteL( const TDesC8& aSipUri );
00156                 
00157                 
00158                 /**
00159                 * CancelInvite
00160                 * CANCEL a previously sent INVITE. If a final
00161                 * response for the INVITE has been sent, the
00162                 * CANCEL request fails.
00163                 */
00164                 IMPORT_C void CancelInviteL();
00165 
00166 
00167                 /**
00168                 * AcceptInvite
00169                 * Send a 200 (OK) response to an INVITE sent
00170                 * by a remote party.
00171                 * @param aIPAddr local ip-address.
00172                 */
00173                 IMPORT_C void AcceptInviteL(const TInetAddr& aIPAddr );
00174 
00175 
00176                 /**
00177                 * DeclineInvite
00178                 * Send a 488 (Not Acceptable Here) response to
00179                 * an INVITE sent by a remote party.
00180                 */
00181                 IMPORT_C void DeclineInviteL();
00182 
00183 
00184                 /**
00185                 * EndSession
00186                 * Terminate the SIP session by sending a BYE
00187                 * request.
00188                 */
00189                 IMPORT_C void EndSessionL();
00190 
00191 
00192                 /**
00193                 * CreateIML
00194                 * Create an instant message and send it to the
00195                 * remote party using the MESSAGE method.
00196                 * @param aMessage The message to be sent.
00197                 * @param aSipUri Address of the recipient.
00198                 */
00199                 IMPORT_C void CreateIML( const TDesC8& aMessage,
00200                                                                  const TDesC8& aSipUri );
00201                                                                  
00202 
00203         public:         // State machine & internal functionality
00204 
00205                 /**
00206                 * IMReceivedL
00207                 * An instant message has been received from the
00208                 * network. Inform the observer.
00209                 * @param aTransaction Contains message elements.
00210                 * Ownership is transferred.
00211                 */
00212                 void IMReceivedL( CSIPServerTransaction* aTransaction );
00213 
00214 
00215                 /**
00216                 * IMReceived
00217                 * A non-leaving version of the IMReceivedL, the
00218                 * possible errors are trapped.
00219                 * @param aTransaction Contains message elements.
00220                 * Ownership is transferred.
00221                 */
00222                 void IMReceived( CSIPServerTransaction* aTransaction );
00223 
00224 
00225                 /**
00226                 * SetCurrentState
00227                 * Sets the active state of the state machine.
00228                 * @param aState The current state.
00229                 */
00230                 void SetCurrentState( CSIPExSIPStateBase* aState );
00231                 
00232     
00233                 /**
00234                 * Connection
00235                 * Sets the active connection.
00236                 */
00237                 CSIPConnection& ConnectionL();
00238 
00239                 /**
00240                 * Profile
00241                 * Returns the enabled profile.
00242                 */
00243                 CSIPProfile& Profile();
00244 
00245         
00246                 /**
00247                 * SetServerTx
00248                 * Sets the current Server Transaction.
00249                 * The ownership is transferred to the Engine.
00250                 * @param aTx The transaction.
00251                 */
00252                 void SetServerTx( CSIPServerTransaction* aTx );
00253 
00254                 /**
00255                 * ServerTx
00256                 * Gets the current Server Transaction.
00257                 */
00258                 CSIPServerTransaction& ServerTx();
00259                 
00260                 
00261                 /**
00262                 * SetClientTx
00263                 * Sets the current Client Transaction.
00264                 * The ownership is transferred to the Engine.
00265                 * @param aTx The transaction.
00266                 */
00267                 void SetClientTx( CSIPClientTransaction* aTx );
00268                 
00269                 /**
00270                 * ClearClientTx
00271                 * Deletes the current Client Transaction.
00272                 */
00273                 void ClearClientTx();
00274 
00275                 /**
00276                 * ClientTx
00277                 * Gets the current Client Transaction.
00278                 */
00279                 CSIPClientTransaction& ClientTx();
00280                 
00281                 
00282                 /**
00283                 * SetDialogAssoc
00284                 * Sets the current Invite Dialog Association.
00285                 * @param aAssoc The Dialog Assoc.
00286                 */
00287                 void SetDialogAssoc( CSIPInviteDialogAssoc& aAssoc );
00288                 
00289                 
00290                 /**
00291                 * DialogAssoc
00292                 * Returns the current Invite Dialog Association.
00293                 */
00294                 CSIPInviteDialogAssoc& DialogAssoc();
00295 
00296                 
00297         public:         // Methods from base classes
00298         
00299 // From MSIPObserver
00300 
00301                 /**
00302                 * IncomingRequest (from MSIPObserver)
00303                 * A SIP request has been received from the network.             
00304                 * @param aIapId The IapId from which
00305                 *        the SIP request was received. 
00306                 * @param aTransaction contains local address,
00307                 *        remote address of a sip message,
00308                 *        as well as optional SIP message method, headers and body.
00309                 *        The ownership is transferred.        
00310         */
00311 
00312                 void IncomingRequest( TUint32 aIapId,
00313                                                           CSIPServerTransaction* aTransaction );
00314 
00315                 /**
00316                 * TimedOut (from MSIPObserver)
00317                 */
00318 
00319                 void TimedOut( CSIPServerTransaction& aSIPServerTransaction );
00320                 
00321                 
00322 // From MSIPConnectionObserver
00323 
00324                 /**
00325                 * IncomingRequest (from MSIPConnectionObserver)
00326                 * A SIP request outside a dialog has been received from the network.
00327         *
00328                 * @param aTransaction SIP server transaction. The ownership is
00329         *   transferred.
00330         */
00331                 void IncomingRequest( CSIPServerTransaction* aTransaction );
00332 
00333                 /**
00334                 * IncomingRequest (from MSIPConnectionObserver)
00335                 * A SIP request within a dialog has been received from the network.
00336                 * The client must resolve the actual dialog association to which
00337                 * this request belongs.
00338                 *
00339                 * @param aTransaction SIP server transaction. The ownership is
00340         *   transferred.
00341                 * @param aDialog the dialog that this transaction belongs to.        
00342                 */
00343                 void IncomingRequest( CSIPServerTransaction* aTransaction,
00344                                                           CSIPDialog& aDialog );
00345 
00346                 /**
00347                 * IncomingResponse (from MSIPConnectionObserver)
00348                 */
00349                 void IncomingResponse( CSIPClientTransaction& aTransaction );
00350 
00351                 /**
00352                 * IncomingResponse (from MSIPConnectionObserver)
00353                 * A SIP response that is within a dialog association or creates
00354                 * a dialog association.
00355         *
00356                 * @param aTransaction contains response elements.
00357                 * @param aDialogAssoc a dialog association.        
00358                 */
00359                 void IncomingResponse( CSIPClientTransaction& aTransaction,
00360                                                            CSIPDialogAssocBase& aDialogAssoc );
00361 
00362         /**
00363                 * IncomingResponse (from MSIPConnectionObserver)
00364                 */
00365                 void IncomingResponse( CSIPClientTransaction& aTransaction,
00366                                                            CSIPInviteDialogAssoc* aDialogAssoc );
00367 
00368 
00369                 /**
00370                 * IncomingResponse (from MSIPConnectionObserver)
00371                 */
00372                 void IncomingResponse( CSIPClientTransaction& aTransaction,
00373                                                            CSIPRegistrationBinding& aRegistration );
00374 
00375 
00376                 /**
00377                 * An asynchronous error has occurred in the stack related to the
00378                 * request indicated by the given transaction.
00379                 *
00380                 * @param aError system wide or sip error code
00381                 * @param aTransaction failed transaction.
00382                 * @param aSIPConnection a SIP connection        
00383                 */
00384                 void ErrorOccured( TInt aError,
00385                                                    CSIPTransactionBase& aTransaction );
00386 
00387                 /**
00388                 * An asynchronous error has occurred in the stack related
00389                 * to the request indicated by the given transaction.
00390         *
00391                 * @param aError system wide or sip error code
00392                 * @param aTransaction the failed transaction.
00393                 * @param aRegistration the failed registration.        
00394                 */
00395                 void ErrorOccured( TInt aError,
00396                                                    CSIPClientTransaction& aTransaction,
00397                                                    CSIPRegistrationBinding& aRegistration );
00398 
00399                 /**
00400                 * An asynchronous error has occured related to a request within
00401                 * an existing dialog.
00402         *
00403                 * @param aError system wide or sip error code
00404                 * @param aTransaction the failed transaction.
00405                 * @param aDialogAssoc the failed dialog associoation.        
00406                 */
00407                 void ErrorOccured( TInt aError,
00408                                                    CSIPTransactionBase& aTransaction,
00409                                                    CSIPDialogAssocBase& aDialogAssoc );
00410 
00411                 /**
00412                 * An asynchronous error has occured related to a refresh 
00413         *
00414                 * @param aError system wide or sip error code
00415                 * @param aSIPRefresh original refresh object.        
00416                 */
00417                 void ErrorOccured( TInt aError, CSIPRefresh& aSIPRefresh );
00418 
00419                 /**
00420                 * An asynchronous error has occured related to a periodical refresh
00421         * that relates to a registration.
00422         *
00423                 * @param aError system wide or sip error code; 
00424                 *                KErrCouldNotConnect if the refresh has failed
00425                 *                due to the suspended connection.
00426                 * @param aRegistration associated registration.
00427                 */
00428                 void ErrorOccured( TInt aError,
00429                                                    CSIPRegistrationBinding& aRegistration );
00430 
00431                 /**
00432                 * An asynchronous error has occured related to a periodical refresh
00433         * that belongs to SIP dialog association.
00434         *
00435                 * @param aError system wide or sip error code; 
00436                 *        KErrCouldNotConnect if the refresh has failed
00437                 *                due to the suspended connection.
00438                 * @param aDialogAssoc SIP dialog association.        
00439                 */
00440                 void ErrorOccured( TInt aError,
00441                                                    CSIPDialogAssocBase& aDialogAssoc );
00442 
00443         /**
00444                 * SIP stack has completed UAC core INVITE transaction 64*T1 seconds
00445         * after the reception of the first 2xx response. No more 2xx responses
00446         * can be received to the issued single INVITE.
00447         *
00448         * If the INVITE transaction does not create a dialog, or the INVITE
00449         * transaction encounters an error, this event will not be sent.
00450         *
00451                 * @param aTransaction a complete UAC core INVITE transaction
00452                 */
00453         void InviteCompleted( CSIPClientTransaction& aTransaction );
00454         
00455         /**
00456         * Invite was canceled with the CANCEL
00457         * @param aTransaction a canceled INVITE UAS transaction
00458         */
00459         void InviteCanceled( CSIPServerTransaction& aTransaction );
00460 
00461                 /**
00462                 * Connection state has changed.
00463         * If connection state has changed to EInactive or EUnavailable,
00464                 * SIP stack has removed all stand-alone SIP refreshes, registrations 
00465                 * and dialog associations that client requested to refresh. Client may
00466                 * re-issue refresh requests (stand-alone, registration or dialog 
00467                 * association related) when connection becomes EActive again.
00468                 * SIP stack also terminates all pending sip client transactions and no
00469         * errors are reported back to the client about the terminated
00470         * transactions nor about removed refreshes in order to avoid event
00471         * flood.
00472                 * 
00473                 * @param aState indicates the current connection state        
00474                 */
00475                 void ConnectionStateChanged( CSIPConnection::TState aState );
00476 
00477                 
00478 // From MSIPProfileRegistryObserver
00479 
00480 
00481         /** 
00482                 * An event related to SIP Profile has accorred
00483                 * @param aProfileId a profile Id
00484                 * @param aEvent an occurred event
00485                 **/
00486         void ProfileRegistryEventOccurred( TUint32 aProfileId, TEvent aEvent );
00487 
00488                 /**
00489                 * An asynchronous error has occurred related to SIP profile
00490                 * Event is send to those observers, who have the
00491                 * corresponding profile instantiated.
00492                 * @param aProfileId the id of failed profile 
00493                 * @param aError an occurred error
00494                 */
00495                 void ProfileRegistryErrorOccurred( TUint32 aProfileId, TInt aError );
00496 
00497 
00498 
00499         public: // Methods internal to the Engine
00500 
00501                 /**
00502                 * CreateToHeaderLC
00503                 * Return a To header object based on URI.
00504                 * @param aSipUri The URI address as a string.
00505                 * @return Pointer to CSIPToHeader instance.
00506                 * Ownership is transferred.
00507                 */
00508                 CSIPToHeader* CreateToHeaderLC( const TDesC8& aSipUri );
00509                 
00510                 /**
00511                 * CreateReqElementsLC
00512                 * Return a RequestElements object based on URI.
00513                 * @param aSipUri The URI address as a string.
00514                 * @return Pointer to CSIPRequestElements instance.
00515                 */
00516                 CSIPRequestElements* CreateReqElementsLC( const TDesC8& aSipUri );
00517                         
00518                 /**
00519                 * CreateMessageElementsLC
00520                 * Instantiate a Message Elements object.
00521                 * @return Pointer to CSIPMessageElements instance.
00522                 * Ownership is transferred.
00523                 */
00524                 CSIPMessageElements* CreateMessageElementsLC();
00525                 
00526                 /**
00527                 * ConvertToUri8LC
00528                 * Convert textual representation of uri to CUri8
00529                 * @return Pointer to CUri8 instance.
00530                 * Ownership is transferred.
00531                 */
00532                 CUri8* ConvertToUri8LC( const TDesC8& aSipUri );
00533 
00534                 /**
00535                 * SdpDocumentLC
00536                 * Instantiate a SDP Document object.
00537                 * @return Pointer to CSdpDocument instance.
00538                 * Ownership is transferred.
00539                 */
00540                 CSdpDocument* SdpDocumentLC();
00541 
00542                 /**
00543                 * SdpBodyL
00544                 * Return SDP message body in textual form.
00545                 * @return Pointer to SDP Document as HBufC8.
00546                 * Ownership is transferred.
00547                 */
00548                 HBufC8* SdpBodyL( CSdpDocument* aDocument );
00549 
00550 
00551                 /**
00552          * Get SDP codec string pool. Open string pool if not opened.
00553                  *
00554          * @return String pool.
00555          */
00556                 RStringPool StringPoolL();
00557 
00558 
00559                 /**
00560                 * IPAddressFromResponseElementsL
00561                 * Get IP Address from the Response Elements
00562                 * received from peer.
00563                 * @param aRespElem The Response Elements.
00564                 */
00565                 const TInetAddr IPAddressFromResponseElementsL(
00566                         const CSIPResponseElements& aRespElem );
00567 
00568 
00569                 /**
00570                 * Observer
00571                 * Return a pointer to the Engine Observer class.
00572                 */
00573                 MSIPExSIPEngineObserver* Observer();
00574                 
00575         private:
00576 
00577                 /**
00578                 * SessionId
00579                 * Return the Session ID
00580                 */
00581                 TInt64 SessionId();
00582                 
00583                 void MediaFieldsL( CSdpDocument* aDocument );
00584                 
00585                 /**
00586                 * CurrentConnection returns currently used connection.
00587                 * Can be used also for checking if connection exists.
00588                 * Returns either iConnection, iNotOwnedConnection or NULL
00589                 */
00590                 CSIPConnection* CurrentConnection();
00591 
00592                 /**
00593                 * Handle SIP profile registration event
00594                 * @param aSIPProfileId id of registered profile
00595                 */
00596                 void HandleProfileRegistered( TUint32 aSIPProfileId );
00597                 
00598                 /**
00599                 * Handle SIP profile deregistration event
00600                 * @param aSIPProfileId id of deregistered profile
00601                 */
00602                 void HandleProfileDeregistered( TUint32 aSIPProfileId );
00603 
00604                 /**
00605                 * Handle SIP profile destruction event.
00606                 * Event is send to those observers, who have the
00607                 * corresponding profile instantiated.
00608                 * @param aSIPProfileId id of profile which was destroyed
00609                 */
00610                 void HandleProfileDestroyed( TUint32 aSIPProfileId );
00611                 
00612 
00613 
00614         private:        // Data
00615 
00616                 TInt64                                          iSessionId;
00617                 TInetAddr                                       iLocalAddr;
00618                 MSIPExSIPEngineObserver*        iObserver;
00619 
00620                 CSIP*                                           iSIP;
00621                 CSIPProfile*                            iProfile;
00622                 CSIPProfileRegistry*            iProfileRegistry;
00623                 CSIPConnection*                         iConnection;
00624                 CSIPInviteDialogAssoc*          iDialogAssoc;
00625 
00626                 CSIPConnection::TState          iConnState;
00627 
00628                 CSIPExSIPStateBase*                     iCurrentState;
00629                 CSIPClientTransaction*          iClientTx;
00630                 CSIPServerTransaction*          iServerTx;
00631 
00632                 // States of the machine
00633                 CSIPExSIPIdleState*                                     iIdle;
00634                 CSIPExSIPClientEstablishingState*       iClientEstablishing;
00635                 CSIPExSIPClientOfferingState*           iClientOffering;
00636                 CSIPExSIPServerOfferingState*           iServerOffering;
00637                 CSIPExSIPServerEstablishingState*       iServerEstablishing;
00638                 CSIPExSIPEstablishedState*                      iEstablished;
00639                 CSIPExSIPTerminatingState*                      iTerminating;
00640                 
00641         };
00642 
00643 #endif  // _SIPEXSIPENGINE_H_

© Nokia 2006

Back to top