realtimenetprots/sipfw/ClientResolver/Server/src/CSIPCRServer.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name          : CSipCRServer.cpp
       
    15 // Part of       : SIP Client Resolver
       
    16 // Version       : 1.0
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDES
       
    22 #include "sipCRclientserver.h"
       
    23 #include "CSipCRServer.h"
       
    24 #include "CSipCRServerSession.h"
       
    25 #include "CSIPCRITCUtility.h"
       
    26 #include "CSIPCRRoutingTable.h"
       
    27 #include "CSIPCRServerCloseTimer.h"
       
    28 #include "CSIPClientResolver.h"
       
    29 #include "sipresolvedclient.h"
       
    30 #include "sipresolvedclient2.h"
       
    31 #include "sipstrings.h"
       
    32 #include "SIPHeaderLookup.h"
       
    33 #include "TSipCRPlatSecPolicy.h"
       
    34 
       
    35 // CONSTANTS
       
    36 const TUint KServerCloseWaitTime = 500; // milliseconds
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CSIPCRServer::NewL
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CSIPCRServer* CSIPCRServer::NewL ()
       
    43 	{
       
    44     CSIPCRServer* self = CSIPCRServer::NewLC();
       
    45     CleanupStack::Pop(self);
       
    46     return self;
       
    47 	}
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CSIPCRServer::NewLC
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CSIPCRServer* CSIPCRServer::NewLC ()
       
    54 	{
       
    55 	CSIPCRServer* self = new(ELeave)CSIPCRServer(EPriorityHigh);
       
    56     CleanupStack::PushL(self);
       
    57     self->ConstructL();
       
    58     return self;
       
    59 	}
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CSIPCRServer::CSipCRServer
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CSIPCRServer::CSIPCRServer (TInt aPriority)
       
    66  : CPolicyServer(aPriority, TSIPCRPlatSecPolicy)
       
    67 	{
       
    68 	}
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CSIPCRServer::ConstructL
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CSIPCRServer::ConstructL ()
       
    75 	{
       
    76 	SIPStrings::OpenL();
       
    77 	SIPHeaderLookup::OpenL();
       
    78 	SIPHeaderLookup::SetConvertToSIPURI();
       
    79 	
       
    80     iActiveScheduler = new (ELeave) CActiveScheduler ();
       
    81     CActiveScheduler::Install (iActiveScheduler);
       
    82 
       
    83     iItcUtility = CSIPCRITCUtility::NewL();
       
    84     iCloseTimer = CSIPCRServerCloseTimer::NewL();
       
    85     iRoutingTable = CSIPCRRoutingTable::NewL();
       
    86     iClientResolver = CSIPClientResolver::NewL();
       
    87     
       
    88     StartL(KSipClientResolverServerName);
       
    89 	}
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CSIPCRServer::~CSIPCRServer
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 CSIPCRServer::~CSIPCRServer ()
       
    96 	{
       
    97 	delete iClientResolver;
       
    98 	delete iRoutingTable;
       
    99 	delete iCloseTimer;
       
   100 	delete iItcUtility;
       
   101 	delete iActiveScheduler;
       
   102 	CActiveScheduler::Install (NULL);
       
   103 	SIPHeaderLookup::Close();
       
   104 	SIPStrings::Close();
       
   105 	REComSession::FinalClose();
       
   106 	
       
   107 #ifdef _BullseyeCoverage
       
   108     // Store coverage measurement
       
   109     cov_write();
       
   110 #endif
       
   111 	}
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CSIPCRServer::IncrementSessions
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CSIPCRServer::IncrementSessions ()
       
   118 	{
       
   119 	if (iCloseTimer->IsActive())
       
   120         {
       
   121         iCloseTimer->Cancel();
       
   122         }
       
   123     iSessionCount++;
       
   124 	}
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CSIPCRServer::DecrementSessions
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CSIPCRServer::DecrementSessions ()
       
   131 	{
       
   132     iSessionCount--;
       
   133 	if (iSessionCount == 0)
       
   134 		{
       
   135 		iCloseTimer->StopActiveSchedulerAfter(KServerCloseWaitTime);
       
   136 		}
       
   137 	}
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CSIPCRServer::ITCUtility
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 CSIPCRITCUtility& CSIPCRServer::ITCUtility ()
       
   144     {
       
   145     return *iItcUtility;
       
   146     }
       
   147     
       
   148 // -----------------------------------------------------------------------------
       
   149 // CSIPCRServer::RoutingTable
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 CSIPCRRoutingTable& CSIPCRServer::RoutingTable ()
       
   153     {
       
   154     return *iRoutingTable;
       
   155     }
       
   156     
       
   157 // -----------------------------------------------------------------------------
       
   158 // CSIPCRServer::ClientResolver
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 CSIPClientResolver& CSIPCRServer::ClientResolver ()
       
   162     {
       
   163     return *iClientResolver;
       
   164     }
       
   165     
       
   166 // ----------------------------------------------------------------------------
       
   167 // CSIPCRServer::LoadPlugin1LC
       
   168 // ----------------------------------------------------------------------------
       
   169 //    
       
   170 CSIPResolvedClient* CSIPCRServer::LoadPlugin1LC( 
       
   171     const TUid& aClientUid,
       
   172     const TUid& aResolverUid )
       
   173     {
       
   174     const TInt KUidWidth = 8;
       
   175     TBuf8<KUidWidth> clientUidBuf;
       
   176     clientUidBuf.AppendNumFixedWidthUC( aClientUid.iUid, EHex, KUidWidth );
       
   177     TEComResolverParams resolverParams;
       
   178     resolverParams.SetDataType( clientUidBuf );
       
   179     CSIPResolvedClient* resolvedClient = NULL;
       
   180     
       
   181     if (aResolverUid == TUid::Null())
       
   182         {
       
   183         resolvedClient = reinterpret_cast< CSIPResolvedClient* >(
       
   184             REComSession::CreateImplementationL( KSIPResolvedClientIFUid,
       
   185                 _FOFF( CSIPResolvedClient, iInstanceKey ),
       
   186                 resolverParams ) );
       
   187         }
       
   188     else
       
   189         {
       
   190         resolvedClient = reinterpret_cast< CSIPResolvedClient* >(
       
   191             REComSession::CreateImplementationL( KSIPResolvedClientIFUid,
       
   192                 _FOFF( CSIPResolvedClient, iInstanceKey ),
       
   193                 resolverParams, aResolverUid ) );        
       
   194         }
       
   195         
       
   196     CleanupStack::PushL(resolvedClient);
       
   197     return resolvedClient;    
       
   198     }
       
   199     
       
   200 // ----------------------------------------------------------------------------
       
   201 // CSIPCRServer::LoadPlugin2LC
       
   202 // ----------------------------------------------------------------------------
       
   203 //    
       
   204 CSIPResolvedClient2* CSIPCRServer::LoadPlugin2LC(
       
   205     const TUid& aImplementationUid )
       
   206     {
       
   207     CSIPResolvedClient2* resolvedClient = 
       
   208         reinterpret_cast< CSIPResolvedClient2* >(
       
   209             REComSession::CreateImplementationL( 
       
   210                 aImplementationUid,
       
   211                 _FOFF( CSIPResolvedClient2, iInstanceKey ) ) );
       
   212     CleanupStack::PushL(resolvedClient);
       
   213     return resolvedClient;    
       
   214     }
       
   215    
       
   216 // ----------------------------------------------------------------------------
       
   217 // CSIPCRServer::RoutingEntryAddedL
       
   218 // ----------------------------------------------------------------------------
       
   219 //    
       
   220 void CSIPCRServer::RoutingEntryAddedL(const TUid& aUid)
       
   221     {
       
   222 	// Inform all the sessions
       
   223 	iSessionIter.SetToFirst();
       
   224     CSIPCRServerSession* session = NULL;
       
   225 	for (CSession2* s=iSessionIter; s!=0; s=iSessionIter++)
       
   226 		{
       
   227 		session = static_cast<CSIPCRServerSession*>(s);
       
   228 		session->RoutingEntryAddedL(aUid);
       
   229 		}
       
   230     }    
       
   231     
       
   232 // -----------------------------------------------------------------------------
       
   233 // CSIPCRServer::RunError
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 TInt CSIPCRServer::RunError(TInt aError)
       
   237 	{
       
   238 	if (aError == KErrBadDescriptor)
       
   239 		{
       
   240         // A bad descriptor error implies a badly programmed client, 
       
   241         // so panic it; otherwise report the error to the client
       
   242 		Message().Panic(KSipCRServerPanic, EBadDescriptor);
       
   243 		}
       
   244 	else
       
   245 		{
       
   246 		Message().Complete(aError);
       
   247 		}
       
   248 	//
       
   249 	// The leave will result in an early return from CServer::RunL(), skipping
       
   250 	// the call to request another message. So do that now in order to keep the
       
   251 	// server running.
       
   252 	ReStart();
       
   253 	return KErrNone; // handled the error fully
       
   254 	}
       
   255 	
       
   256 // -----------------------------------------------------------------------------
       
   257 // CSIPCRServer::NewSessionL
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 CSession2* CSIPCRServer::NewSessionL(const TVersion &aVersion,
       
   261                                      const RMessage2& /*aMessage*/) const
       
   262 	{
       
   263 	// check we're the right version
       
   264 	if (!User::QueryVersionSupported(TVersion(KSipCRServerMajorVersionNumber,
       
   265                                               KSipCRServerMinorVersionNumber,
       
   266                                               KSipCRServerBuildVersionNumber),
       
   267                                               aVersion))
       
   268 		{
       
   269 		User::Leave(KErrNotSupported);
       
   270 		}
       
   271 	// make new session
       
   272     return CSIPCRServerSession::NewL(const_cast<CSIPCRServer&>(*this));
       
   273   	}
       
   274 
       
   275 //  End of File