commsprocess/commsrootserverconfig/rootsrv/c32exe.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2003-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 // The Rootserver executeable. Runs the Rootserver from c32rootsrv.dll.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include <rsshared.h>
       
    24 #include <cflog.h>
       
    25 #include <commsdattypesv1_1.h>	// for initialising CommsDat
       
    26 #include "c32Exe.h"
       
    27 using namespace RootServer;
       
    28 
       
    29 #include <comms-infras/commsdebugutility.h>
       
    30 
       
    31 
       
    32 __CFLOG_STMT(_LIT8(KLogSubSysRS, "RootServer");) // subsystem name
       
    33 
       
    34 CCommsProviderModule* CC32ProviderModule::NewL(CRootServer* aRootServer, 
       
    35 									const TRSStartModuleParams& aParams, 
       
    36 								   	HBufC8* aIniData)
       
    37     /** Creates a new instance of a CPM.
       
    38 	 @param aRootServer The root server object
       
    39 	 @param aParams The data used to load the module
       
    40 	 @param aIniData The initialisation data for the module
       
    41      */
       
    42     {
       
    43 
       
    44     CC32ProviderModule* pCPM = new (ELeave) CC32ProviderModule();
       
    45     CleanupStack::PushL(pCPM);
       
    46     pCPM->ConstructL(aRootServer, aParams, aIniData);
       
    47     CleanupStack::Pop(pCPM);
       
    48     return pCPM;
       
    49     }
       
    50 
       
    51 TInt CC32ProviderModule::CreateModuleThread(const TDesC& aName, TThreadFunction aOtherThreadFunction,
       
    52 						TInt aStackSize, RHeap* aHeap, TAny* aModuleArgs)
       
    53     {
       
    54     return iRCFThread.Create(aName, aOtherThreadFunction, aStackSize, aHeap, aModuleArgs);
       
    55     }
       
    56 
       
    57 CRootServer* CC32RootServer::NewL(const TRootServerStartupInfo& aRootServerStartupInfo)
       
    58     /** Create new rootserver instance.
       
    59      This is the only way of instantiation
       
    60      @internalComponent
       
    61      @param aRootServerStartupInfo Information containing name of the server and priority of the server active object.
       
    62      */
       
    63     {
       
    64     CC32RootServer* pS=new (ELeave) CC32RootServer(aRootServerStartupInfo.iPriority);
       
    65     CleanupStack::PushL(pS);
       
    66 	pS->iCommsProviderModuleCtorL = CC32ProviderModule::NewL;
       
    67     pS->ConstructL(aRootServerStartupInfo);
       
    68 	// Now that we're guaranteed to be a singleton initialise CommsDat
       
    69 	__CFLOG(KLogSubSysRS, KLogCode, _L8("RunRootServer - Initializing Commsdat"));
       
    70 	CommsDat::CMDBSession* ptrCommsdatSession = NULL;
       
    71 	TRAPD(result, ptrCommsdatSession = CommsDat::CMDBSession::NewL(KCDVersion1_2));
       
    72 	if (result == KErrNone)
       
    73 		{
       
    74 		result = ptrCommsdatSession->PublishProperties();
       
    75 		if(result != KErrNone)
       
    76 			{
       
    77 			__CFLOG_1(KLogSubSysRS, KLogCode, _L8("RunRootServer - Error %d in CMDBSession::PublishProperties"), result);
       
    78 			}
       
    79 		delete ptrCommsdatSession;
       
    80 		}
       
    81 	else
       
    82 		{
       
    83 		__CFLOG_1(KLogSubSysRS, KLogCode, _L8("RunRootServer - Error %d creating Commsdat object"), result);
       
    84 		}
       
    85 	__CFLOG(KLogSubSysRS, KLogCode, _L8("RunRootServer - Commsdat initialized"));
       
    86 
       
    87     CleanupStack::Pop(pS);
       
    88     return pS;
       
    89 	}
       
    90 
       
    91 CC32RootServer::~CC32RootServer()
       
    92     {
       
    93 #ifdef SYMBIAN_ZERO_COPY_NETWORKING    
       
    94 	iCommsBufPond.Close();
       
    95 #else
       
    96 	delete iMBufManager;
       
    97 #endif // SYMBIAN_ZERO_COPY_NETWORKING	
       
    98     }
       
    99    
       
   100 #ifdef _DEBUG
       
   101 TInt CC32RootServer::RunError(TInt aError)
       
   102 	{
       
   103 	__CFLOG_1(KLogSubSysRS, KLogCode, _L8("CRootServer::RunError:%d" ), aError);
       
   104 	return aError;
       
   105 	}
       
   106 #endif // _DEBUG
       
   107 
       
   108 TInt CC32RootServer::AdjustMBufPool(const TRSSetMBufMnr &aMBufParamsPckg)
       
   109     /** Adjust the buffer pool size.
       
   110   	 Doesn't actually adjust the pool, can only be called when there
       
   111      is no pool instantiated. If a pool is already instantiated, returns KErrInUse.
       
   112 	 @internalComponent
       
   113      @param aBufPoolSize The new size of the buffer pool in bytes.
       
   114      @return An error code
       
   115      */
       
   116     {
       
   117     const TRSSetMBufMnrContainer &mbufParams = aMBufParamsPckg();
       
   118     __CFLOG_2(KLogSubSysRS, KLogCode, _L8("CRootServer - AdjustMBufPool to %d Init and %d Max."),
       
   119      mbufParams.iInitSize, mbufParams.iMaxSize);
       
   120 
       
   121     // Can't do this if it is already in use
       
   122     if(CpmCount()>0)
       
   123         return KErrInUse;
       
   124 #ifndef SYMBIAN_ZERO_COPY_NETWORKING  
       
   125    if(iInitMBufPoolSize == mbufParams.iInitSize && iMaxMBufPoolSize == mbufParams.iMaxSize)
       
   126       {
       
   127 	  return KErrNone;
       
   128       }
       
   129       
       
   130 	  // Finally register new size.
       
   131 	  iInitMBufPoolSize = mbufParams.iInitSize;
       
   132 	  iMaxMBufPoolSize = mbufParams.iMaxSize;
       
   133 
       
   134 	  // Delete MBufManager, it will be lazy loaded with new value when needed
       
   135 	  if(iMBufManager!=NULL)
       
   136 	  	{
       
   137  		delete iMBufManager;
       
   138 	    iMBufManager=NULL;
       
   139         }
       
   140 #endif // SYMBIAN_ZERO_COPY_NETWORKING
       
   141     return KErrNone;    
       
   142     }
       
   143 
       
   144 TInt CC32RootServer::AdjustMBufSizeAllocInfo(const TRSAddMBufAllocInfo &aMBufParamsPckg)
       
   145     /** Adjust (aka add) the mbuf size alloc info
       
   146 	 @internalComponent
       
   147      @param aBufPoolSize The new size of the buffer pool in bytes.
       
   148      @return An error code
       
   149      */
       
   150     {
       
   151 	const TRSAddMBufAllocInfoContainer &mBufAllocSizeInfo = aMBufParamsPckg();
       
   152 	__CFLOG_4(KLogSubSysRS, KLogCode, _L8("CRootServer::AdjustMBufSizeAllocInfo() - mbufSize=%d initialAlloc=%d minGrowth=%d growthThreshold=%d"),
       
   153 		mBufAllocSizeInfo.iMBufSize, mBufAllocSizeInfo.iInitialAllocation, mBufAllocSizeInfo.iMinGrowth, mBufAllocSizeInfo.iGrowthThreshold);
       
   154 
       
   155     // store params - they will be retrieved  set during the lazy load
       
   156 	return iMBufSizeAllocInfo.Append(mBufAllocSizeInfo);
       
   157     }
       
   158 
       
   159 void CC32RootServer::LazyLoadL()
       
   160     /** Instantiate the MBuf Manager.
       
   161      If the MBufManager is not already running, then create a new
       
   162      instance of it.
       
   163 	 @internalComponent
       
   164      */
       
   165     {
       
   166 #ifdef SYMBIAN_ZERO_COPY_NETWORKING    
       
   167     if(TCommsBufPondTLSOp::Get().IsNull())
       
   168         {
       
   169         __CFLOG_0(KLogSubSysRS, KLogCode, 
       
   170         	_L8("CRootServer - Lazy loading CommsBuf Pond."));
       
   171 			RArray<TCommsBufPoolCreateInfo> bufPoolCreateInfoArray;
       
   172 			// configure the mbuf size allocation info
       
   173 			for (int i=0; i < iMBufSizeAllocInfo.Count(); i++)
       
   174 				{
       
   175 				TRSAddMBufAllocInfoContainer &allocInfo = iMBufSizeAllocInfo[i];
       
   176 				__CFLOG_4(KLogSubSysRS, KLogCode,
       
   177 					_L8("CRootServer::LazyLoadMBufManagerL(); - about to add mbuf size alloc info - mbufSize=%d initialAlloc=%d minGrowth=%d growthThreshold=%d"),
       
   178 					allocInfo.iMBufSize, allocInfo.iInitialAllocation,
       
   179 					allocInfo.iMinGrowth, allocInfo.iGrowthThreshold);
       
   180 					TCommsBufPoolCreateInfo createInfo;
       
   181 					createInfo.iBufSize = allocInfo.iMBufSize;
       
   182 					createInfo.iInitialBufs = allocInfo.iInitialAllocation;
       
   183 					createInfo.iGrowByBufs = allocInfo.iMinGrowth;
       
   184 					createInfo.iMinFreeBufs = allocInfo.iGrowthThreshold;
       
   185 					createInfo.iCeiling = allocInfo.iPoolCeiling;
       
   186 					bufPoolCreateInfoArray.AppendL(createInfo);
       
   187 				}
       
   188 			User::LeaveIfError(iCommsBufPond.Open(bufPoolCreateInfoArray));
       
   189         }
       
   190 #else
       
   191     if(iMBufManager==NULL)
       
   192 	    {
       
   193 	    __CFLOG_2(KLogSubSysRS, KLogCode, 
       
   194 	    _L8("CRootServer - Lazy loading MBuf Manager. %d initial bytes - can grow to %d bytes."),
       
   195 		iInitMBufPoolSize,iMaxMBufPoolSize);
       
   196 
       
   197 		iMBufManager = CMBufManager::NewL(iMaxMBufPoolSize, iMBufSizeAllocator);
       
   198     
       
   199 		if (iMBufSizeAllocator)
       
   200 	        {
       
   201 	        // configure the mbuf size allocation info
       
   202 			for (int i=0; i < iMBufSizeAllocInfo.Count(); i++)
       
   203 		        {
       
   204 		        TRSAddMBufAllocInfoContainer &allocInfo = iMBufSizeAllocInfo[i];
       
   205 		        __CFLOG_4(KLogSubSysRS, KLogCode,
       
   206 	            _L8("CRootServer::LazyLoadMBufManagerL(); - about to add mbuf size alloc info - mbufSize=%d initialAlloc=%d minGrowth=%d growthThreshold=%d"),
       
   207 				allocInfo.iMBufSize, allocInfo.iInitialAllocation,
       
   208 		        allocInfo.iMinGrowth, allocInfo.iGrowthThreshold);
       
   209 	            iMBufSizeAllocator->AddL(allocInfo.iMBufSize, allocInfo.iInitialAllocation,
       
   210 	            allocInfo.iMinGrowth, allocInfo.iGrowthThreshold);
       
   211 				}
       
   212 
       
   213 			iMBufSizeAllocator->Commit();
       
   214 		    }
       
   215 			iMBufSizeAllocInfo.Close();
       
   216 		}
       
   217 
       
   218 #endif // SYMBIAN_ZERO_COPY_NETWORKING        
       
   219     }
       
   220   
       
   221     
       
   222 TBool CC32RootServer::IsCallerConfigurator(const CRootServerSession* aSession, const RMessage2& aMessage)
       
   223 	/** If The Configurator has been determined then any other session asking isn't. Otherwise the 
       
   224 	first configurator process to ask becomes The Configurator. Note that this would fail if The
       
   225 	Configurator opened a second session, but it doesn't (and it's internalTech)
       
   226 	*/
       
   227 	{
       
   228 	if(!iTheConfiguratorSession)
       
   229 		{
       
   230 		RThread client;
       
   231 		TInt err = aMessage.Client(client);
       
   232 		if(err == KErrNone)
       
   233 			{
       
   234 			static _LIT_SECURITY_POLICY_S1(configuratorPolicy, KUidC32StartProcess, ECapabilityProtServ);
       
   235 			if(configuratorPolicy.CheckPolicy(client))
       
   236 				{
       
   237 				iTheConfiguratorSession = aSession;
       
   238 				}
       
   239 			client.Close();
       
   240 			}
       
   241 		}
       
   242 	return iTheConfiguratorSession == aSession;
       
   243 	}
       
   244 
       
   245 void CC32RootServer::DisconnectSession(const CRootServerSession* aSession)
       
   246 	{
       
   247 	if(iTheConfiguratorSession == aSession)
       
   248 		{
       
   249 		iTheConfiguratorSession = NULL;
       
   250 		}
       
   251 	}    
       
   252 
       
   253 CSession2* CC32RootServer::NewSessionL(const TVersion &aVersion, const RMessage2& /*aMessage*/) const
       
   254     /** Create new session object.
       
   255      @internalComponent
       
   256      */
       
   257     {
       
   258     __CFLOG(KLogSubSysRS, KLogCode,_L8("CC32RootServer - NewSession"));
       
   259 
       
   260     TVersion v(TVersion(KRS32MajorVersionNumber,KRS32MinorVersionNumber,KRS32BuildVersionNumber));
       
   261     TBool r = User::QueryVersionSupported(v, aVersion);
       
   262     if (r==EFalse)
       
   263         User::Leave(KErrNotSupported);
       
   264     CC32RootServerSession* p = new(ELeave) CC32RootServerSession(this);
       
   265     return p;
       
   266     }
       
   267 
       
   268 
       
   269 CC32RootServerSession::CC32RootServerSession(const CRootServer* aRootServer):CRootServerSession(aRootServer)
       
   270 	{
       
   271 	}
       
   272 
       
   273 CC32RootServerSession::~CC32RootServerSession()
       
   274 	{
       
   275 	}
       
   276 
       
   277 void CC32RootServerSession::ServiceL(const RMessage2& aMessage)
       
   278 	{
       
   279     TInt result = KErrGeneral;
       
   280     TBool completeNow = ETrue;
       
   281     switch ((aMessage.Function()))
       
   282 		{
       
   283 		case RSSetMBufPoolSize:
       
   284 			result = SetMBufPoolSize(aMessage);
       
   285 			break;
       
   286 	
       
   287 		case RSAddMBufAllocInfo:
       
   288 			result = AddMBufAllocInfo(aMessage);
       
   289 			break;
       
   290 	
       
   291 		case RSIsCallerConfigurator:
       
   292 			result = IsCallerConfigurator(aMessage);
       
   293 			break;			
       
   294 			
       
   295 		case RSDbgFailNextMbuf:
       
   296 		case RSDbgSetMbufPoolLimit:
       
   297 		case RSDbgCheckMbuf:
       
   298 		case RSDbgMbufFreeSpace:
       
   299 		case RSDbgMbufTotalSpace:
       
   300 			result = KErrNotSupported;
       
   301 			break;
       
   302 			
       
   303 		default:
       
   304 			CRootServerSession::ServiceL(aMessage);
       
   305 			completeNow = EFalse;
       
   306 			break;
       
   307 		}
       
   308     
       
   309     if(completeNow)
       
   310             {
       
   311             aMessage.Complete(result);
       
   312             }
       
   313 	}
       
   314 
       
   315 TInt CC32RootServerSession::IsCallerConfigurator(const RMessage2& aMessage)
       
   316 	{
       
   317 	return (TInt) iRootServer->IsCallerConfigurator(this, aMessage);
       
   318 	}
       
   319 
       
   320 TInt CC32RootServerSession::SetMBufPoolSize(const RMessage2& aMessage)
       
   321     {
       
   322     // Do the dirty business and return the result
       
   323     TInt ret;
       
   324     TRSSetMBufMnr params;
       
   325     ret = aMessage.Read(0,params);
       
   326     if (ret != KErrNone)
       
   327     	{
       
   328     	return ret;
       
   329     	}
       
   330     return (static_cast <CC32RootServer*> (iRootServer))->AdjustMBufPool(params);
       
   331     }
       
   332 
       
   333 // set the mbuf size allocation information
       
   334 TInt CC32RootServerSession::AddMBufAllocInfo(const RMessage2& aMessage)
       
   335     {
       
   336     TRSAddMBufAllocInfo params;
       
   337     TInt ret = aMessage.Read(0, params);
       
   338     if (ret != KErrNone)
       
   339     	{
       
   340     	return ret;
       
   341     	}
       
   342     return (static_cast <CC32RootServer*> (iRootServer))->AdjustMBufSizeAllocInfo(params);
       
   343     }
       
   344 
       
   345 
       
   346 TInt E32Main()
       
   347 /** Life starts here. ONly purpose is to run RunRootServer() from c32rootsrv.dll
       
   348 */
       
   349     {
       
   350 	__FLOG_DECLARATION_VARIABLE;
       
   351 	__FLOG_STMT( _LIT8( KRSLogSubSys, "RootServer" ) );
       
   352 	__FLOG_STMT( _LIT8( KRSLogComp, "event" ) );
       
   353 	__FLOG_OPEN( KRSLogSubSys, KRSLogComp );  
       
   354 	__FLOG( _L8("C32exe.exe - E32Main calling RunRootServer in DLL") );
       
   355 	__FLOG_CLOSE;
       
   356  
       
   357  	TRootServerStartupInfo info;
       
   358  	info.iPriority = CActive::EPriorityStandard;
       
   359  	info.iServerName = KRootServerName;
       
   360  	info.iRootServerCtor = CC32RootServer::NewL;
       
   361  	info.iDeathKey = KUidC32RootModuleDeathKey;
       
   362 	info.iLeakKey.iUid = KUidCommsModuleLeakCounter;
       
   363 	info.iProcessKey = KUidCommsProcess;
       
   364 	return RunRootServer(info); // Load Root Server. Blocks by starting the active scheduler
       
   365     }
       
   366