multimediacommsengine/mmcesrv/mmceserver/inc/mcesipmanager.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 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 
       
    20 
       
    21 #ifndef CMCESIPMANAGER_H
       
    22 #define CMCESIPMANAGER_H
       
    23 
       
    24 #include "mcesrv.h"
       
    25 #include "mceclientserver.h"
       
    26 #include "mcemediaobserver.h"
       
    27 #include "mceclientresolver.h"
       
    28 #include <es_sock.h>
       
    29 #include <sipobserver.h>
       
    30 #include <sipprofileregistryobserver.h>
       
    31 #include <e32base.h>
       
    32 
       
    33 //  FORWARD DECLARATION
       
    34 class CSIP;
       
    35 class CSIPProfile;
       
    36 class CSIPHttpDigest;
       
    37 class CMceServerCore;
       
    38 class CMceSipConnection;
       
    39 class CMceCsSubSession;
       
    40 class CMceCsSessionImplementation;
       
    41 class CMceCsSession;
       
    42 class CMceMediaManager;
       
    43 class TMceIds;
       
    44 class CSIPProfileRegistry;
       
    45 class CSIPServerTransaction;
       
    46 class CSIPClientTransaction;
       
    47 class CSIPInviteDialogAssoc;
       
    48 class CSIPNotifyDialogAssoc;
       
    49 class CMceSipStateMachine;
       
    50 class CMceTimerManager;
       
    51 
       
    52 /**
       
    53 * This class provides life-cycle management of 
       
    54 * SIP sessions and SIP events. It also acts as an
       
    55 * observer for SIP API, SIP Client resolver and
       
    56 * Media Mananger.
       
    57 *
       
    58 *  @lib 
       
    59 *  @since
       
    60 */
       
    61 class CMceSipManager : public CBase,
       
    62                        public MSIPObserver,
       
    63                        public MSIPProfileRegistryObserver,
       
    64                        public MMceMediaGeneralObserver,
       
    65                        public MMceClientResolverObserver
       
    66 	{	
       
    67 public: // Constructors and destructor
       
    68 
       
    69 	/**
       
    70 	* Two-phased constructor.
       
    71 	* @param aServerCore, reference to server core.
       
    72 	*/
       
    73 	static CMceSipManager* NewL( CMceServerCore& aServerCore );
       
    74 
       
    75 	/**
       
    76 	* Two-phased constructor.
       
    77 	* @param aServerCore, reference to server core.
       
    78 	*/
       
    79 	static CMceSipManager* NewLC( CMceServerCore& aServerCore );
       
    80 
       
    81 	/**
       
    82 	* Destructor.
       
    83 	*/
       
    84 	~CMceSipManager();
       
    85 
       
    86 public: // from MSIPObserver
       
    87 
       
    88     /**
       
    89     * A SIP request has been received from the network.        
       
    90     * @pre aTransaction != 0
       
    91     * @param aIapId The IapId from which the SIP request was received.
       
    92     * @param aTransaction contains local address, remote address of a SIP
       
    93     *        message, as well as optional SIP message method, headers and
       
    94     *        body. The ownership is transferred.
       
    95     */
       
    96 	void IncomingRequest(TUint32 aIapId,
       
    97 		                 CSIPServerTransaction* aTransaction);
       
    98 
       
    99     /**
       
   100     * The received SIP request time-outed and it is invalid i.e. cannot be used
       
   101     * anymore.
       
   102     * This will be called if the user fails to create a SIP connection
       
   103     * and does not send an appropriate SIP response.
       
   104     * @param aTransaction The time-outed transaction.
       
   105     */
       
   106     void TimedOut(CSIPServerTransaction& aTransaction);
       
   107 
       
   108 
       
   109 public: // from MMceClientResolverObserver
       
   110 
       
   111 
       
   112     /**
       
   113     *  Called when client discovery subsystem has resolved
       
   114     *  the client the transaction should go to
       
   115     *
       
   116     *  @param aClientUid Client's uid
       
   117     *  @param aConnection the connection used
       
   118     *  @param aRequest the transaction
       
   119     */
       
   120     void IncomingResolvedRequest( TUid aClientUid,
       
   121                                   CMceSipConnection& aConnection,
       
   122                                   CSIPServerTransaction* aRequest );
       
   123 
       
   124 
       
   125 public: //from MSIPProfileRegistryObserver 
       
   126 	
       
   127 	/** 
       
   128 	* An event related to SIP Profile has accorred
       
   129 	* @param aProfileId a profile Id
       
   130 	* @param aEvent an occurred event
       
   131 	**/
       
   132 	void ProfileRegistryEventOccurred(
       
   133 	            TUint32 aProfileId, 
       
   134 	            MSIPProfileRegistryObserver::TEvent aEvent);
       
   135 
       
   136 	/**
       
   137 	* An asynchronous error has occurred related to SIP profile
       
   138 	* Event is send to those observers, who have the
       
   139 	* corresponding profile instantiated.
       
   140 	* @param aProfileId the id of failed profile 
       
   141 	* @param aError an occurred error
       
   142 	*/
       
   143 	void ProfileRegistryErrorOccurred(TUint32 aProfileId, TInt aError);
       
   144 
       
   145 public: // from MMceMediaGeneralObserver
       
   146 
       
   147 	/**
       
   148     * Callback function to indicate about media error
       
   149     * @param aError, error occured	 
       
   150     */
       
   151 	void MediaError ( TInt aError );
       
   152 
       
   153     
       
   154 public: // New
       
   155 
       
   156 	/**
       
   157 	* Reserves new dialog id
       
   158 	* @return new dialog id
       
   159 	*/
       
   160     TUint32 NextDialogId();
       
   161     
       
   162 	/**
       
   163 	* Returns ETrue, if manager will consume the transaction
       
   164 	* @param aTransaction the pending transaction
       
   165 	* @return ETrue, if manager will consume the transaction
       
   166 	*/
       
   167     TBool Consumes( CSIPServerTransaction& aTransaction );
       
   168     
       
   169 	/**
       
   170 	* Registers a client
       
   171 	* @param aClientSession the client
       
   172 	*/
       
   173     void RegisterClientL( CMceCsSession& aClientSession );
       
   174 
       
   175 	/**
       
   176 	* Un-registers client
       
   177 	* @param aClientSession the client
       
   178 	*/
       
   179     void UnRegisterClient( CMceCsSession& aClientSession );
       
   180     
       
   181 	/**
       
   182 	* Creates outgoing (sub) session
       
   183 	* @param aClientSession the client
       
   184     * @param aIds set of ids defining ITC call context
       
   185 	* @param aParams parameter for dialog
       
   186 	* @return sub session 
       
   187 	*/
       
   188     CMceCsSubSession* CreateSubSessionL( CMceCsSession& aClientSession, 
       
   189                                          TMceIds& aIds,
       
   190                                          CDesC8Array& aParams );
       
   191     
       
   192 	/**
       
   193 	* Creates incoming (sub) session
       
   194 	* @param aTransaction incoming request, which trigged creation
       
   195     * @param aConnection SIP connection to which session will be attached
       
   196 	* @return sub session 
       
   197 	*/
       
   198     void CreateSubSessionL( CSIPServerTransaction* aTransaction,
       
   199                             CMceSipConnection& aConnection );
       
   200     
       
   201 	/**
       
   202 	* Unregisters sub session
       
   203 	* @param aSubSession sub session
       
   204 	*/
       
   205     void UnRegisterSubSession( CMceCsSubSession& aSubSession );
       
   206 
       
   207     /**
       
   208 	* Returns media mananger instance
       
   209 	* @return media mananger
       
   210 	*/
       
   211     CMceMediaManager& MediaManager();
       
   212     
       
   213 	/**
       
   214 	* Returns timer mananger instance
       
   215 	* @return timer mananger
       
   216 	*/
       
   217     CMceTimerManager& TimerManager();
       
   218     
       
   219 	/**
       
   220 	* Returns SIP client instance
       
   221 	* @return SIP client
       
   222 	*/
       
   223     CSIP& SIPClient();
       
   224 
       
   225 	/**
       
   226 	* Adds orphan sub session
       
   227 	* @param aSubSession sub session
       
   228 	*/
       
   229     void AddOrphanSubSessionL( CMceCsSubSession* aSubSession );
       
   230     
       
   231     /*
       
   232     * get Orphan Session's Count
       
   233     * @return number of orphan subsessions.
       
   234     */  
       
   235     TInt OrphanSubSessionCount();
       
   236     
       
   237 	/**
       
   238 	* Cleans up orphans sub sessions
       
   239 	*/
       
   240     void Cleanup();
       
   241     
       
   242     /**
       
   243 	* Creates incoming sub session
       
   244 	* @param aTransaction incoming request, which trigged creation
       
   245 	* @param aClient resolved client
       
   246 	* @param aConnection IP connection to which session will be attached
       
   247 	*/
       
   248     void CreateSubSessionL( CSIPServerTransaction* aTransaction,
       
   249                             CMceCsSession& aClient,
       
   250                             CMceSipConnection& aConnection,
       
   251                             CMceCsSubSession* aAssocSession = NULL );
       
   252 	
       
   253 	RSocketServ& SocketServ();
       
   254 	
       
   255 private:
       
   256 
       
   257 	CMceSipManager (CMceServerCore& aServerCore);
       
   258 	void ConstructL ();
       
   259 	CSIPProfile& ProfileL( TUint32 aProfileId );
       
   260     CSIPProfile& ProfileL( TUint32 aIapId, 
       
   261                            const CUri8& aRequestUri );
       
   262     CMceSipConnection& ConnectionL( CSIPProfile& aProfile );
       
   263 	CMceSipConnection& ConnectionL( TUint32 aIAPId );    
       
   264     TInt FindProfileById( RPointerArray<CSIPProfile>& aProfiles, TUint32 profileId );
       
   265     TInt FindProfileByRequestUriL( RPointerArray<CSIPProfile>& aProfiles, 
       
   266                                    const CUri8& aRequestUri );
       
   267                                    
       
   268     TUint32 ChannelL( CSIPServerTransaction& aRequest );
       
   269 
       
   270 	/**
       
   271     * When a profile has been updated and its data has been read from Profile
       
   272     * server to aNewProfile, update the sub sessions that point to the old
       
   273     * profile instance, so that they will point to the new instance.
       
   274     * @param aNewProfile Profile's current data
       
   275     * @param aOldProfile Profile's data before it was updated
       
   276     */
       
   277     void UpdateProfileToSubSessions( CSIPProfile& aNewProfile,
       
   278 									 CSIPProfile& aOldProfile );
       
   279 
       
   280 private: // NOT owned Data
       
   281 
       
   282     //MCE server core
       
   283 	CMceServerCore& iServerCore;
       
   284     //all clients registered to MCE server
       
   285     RPointerArray<CMceCsSession> iClients;
       
   286     
       
   287 private: // Owned Data
       
   288 
       
   289     //SIP connections
       
   290 	RPointerArray<CMceSipConnection> iSIPClientConnections;
       
   291     //SIP instance
       
   292 	CSIP* iSIP;
       
   293     //media manager
       
   294 	CMceMediaManager* iMediaManager;
       
   295     //profile registry
       
   296 	CSIPProfileRegistry* iProfileRegistry;
       
   297     //SIP session FSM
       
   298 	CMceSipStateMachine* iStateMachine;
       
   299     //profiles in use
       
   300 	RPointerArray<CSIPProfile> iProfiles;
       
   301 	//next dialog id
       
   302 	TUint32 iNextDialogId;
       
   303 	//client resolver
       
   304 	CMceClientResolver* iClientResolver;
       
   305 	//orphan sub sessions
       
   306 	CMceCsSessionImplementation* iOrphanSubSessions;
       
   307     //timer manager
       
   308     CMceTimerManager* iTimerManager;
       
   309     // Socket server handle    
       
   310     RSocketServ iSocketServ;
       
   311 
       
   312 	//definitions for unit testing
       
   313 	MCESRV_UT_DEFINITIONS
       
   314 	};
       
   315 
       
   316 #endif // CMCESIPMANAGER_H
       
   317 
       
   318 // End of File