commonuisupport/uikon/srvsrc/EIKSRVS.CPP
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 1997-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 // EIKSRV.CPP
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <bautils.h>
       
    19 #include <eiksrvs.h>
       
    20 #include <eiksrv.h>
       
    21 #include <eiksvdef.h>
       
    22 #include <eikdebug.h>
       
    23 #include <e32hal.h>
       
    24 #include <eikdll.h>
       
    25 #include "EIKNFYSV.H"
       
    26 #include "EIKBAKSV.H"
       
    27 #include "EIKALSRV.H"
       
    28 #include "EIKUNDER.H"
       
    29 #include <c32comm.h>
       
    30 #include <s32file.h>
       
    31 #include <apasvst.h>
       
    32 #include <basched.h>
       
    33 #include <apgcli.h>
       
    34 #include <eikenv.h>
       
    35 
       
    36 #if defined(_DEBUG) // for the HAL::Get call in EikDll::RunAppInsideThread to pre-allocate its heap-cell before any OOM testing is started
       
    37 #include <hal.h>
       
    38 #include <hal_data.h>
       
    39 #endif
       
    40 
       
    41 
       
    42 /**
       
    43 Local static function run directly from entry point.  Starts up server.
       
    44 @internalComponent
       
    45 */
       
    46 static TInt RunServer()
       
    47 	{
       
    48 	TBool oomTestingOnEiksrvStartUp=EFalse;
       
    49 #if defined(UIKON_OOM_TESTING)
       
    50 	User::__DbgMarkStart(RHeap::EUser);
       
    51 	CEikDebugPreferences* debugPreferences=CEikDebugPreferences::New();
       
    52 	if (debugPreferences!=NULL)
       
    53 		{
       
    54 		RFs fileServerSession;
       
    55 		if (fileServerSession.Connect()==KErrNone)
       
    56 			{
       
    57 			if (debugPreferences->Restore(fileServerSession)==KErrNone)
       
    58 				{
       
    59 				oomTestingOnEiksrvStartUp=(debugPreferences->Flags()&CEikDebugPreferences::EFlagOOMTestingOnEiksrvStartUp);
       
    60 				}
       
    61 			}
       
    62 		fileServerSession.Close();
       
    63 		delete debugPreferences;
       
    64 		}
       
    65 	User::__DbgMarkEnd(RHeap::EUser, 0);
       
    66 #endif
       
    67 
       
    68 #if defined(_DEBUG)
       
    69 	{
       
    70 	TInt notUsed;
       
    71 	HAL::Get(HALData::EDisplayColors, notUsed); // this is to pre-allocate the heap-cell that certain HAL functions leave lying around (without actually orphaning it) - if we don't do this then the User::__DbgMarkEnd near the end of the loop below will panic because of this heap-cell
       
    72 	}
       
    73 #endif
       
    74 
       
    75 
       
    76 	TInt error=User::RenameThread(EIKAPPUI_SERVER_THREAD_NAME);
       
    77 	if (error!=KErrNone)
       
    78 		{
       
    79 		return error;
       
    80 		}
       
    81 	for (TInt failRate=1; ; ++failRate)
       
    82 		{
       
    83 		TBool tryAgain=EFalse;
       
    84 		User::__DbgMarkStart(RHeap::EUser);
       
    85 		if (oomTestingOnEiksrvStartUp)
       
    86 			{
       
    87 			__SHOW_FAIL_RATE(_L("OOM testing on Eiksrv start up (fail rate %d)"), failRate);
       
    88 			User::__DbgSetAllocFail(RHeap::EUser, RHeap::EFailNext, failRate);
       
    89 			}
       
    90 		TInt error=KErrNoMemory;
       
    91 		CEikonEnv* coe=new CEikServEnv;
       
    92 		if ((coe!=NULL) && (User::TrapHandler()!=NULL))
       
    93 			{
       
    94 			TRAP(error,
       
    95 				coe->ConstructL();
       
    96 				CEikServAppUiServer::NewL()); // the object created by CEikServAppUiServer::NewL is owned by CEikServEnv's iServer
       
    97 			}
       
    98 		if (oomTestingOnEiksrvStartUp)
       
    99 			{
       
   100 			TAny* const pointer=User::Alloc(1);
       
   101 			User::Free(pointer);
       
   102 			if (pointer!=NULL)
       
   103 				{
       
   104 				tryAgain=ETrue;
       
   105 				}
       
   106 			}
       
   107 		if ((error==KErrNone) && !tryAgain)
       
   108 			{
       
   109 			RProcess::Rendezvous(KErrNone);
       
   110 			coe->ExecuteD();
       
   111 			}
       
   112 		else
       
   113 			{
       
   114 			if (coe!=NULL)
       
   115 				{
       
   116 				coe->DestroyEnvironment();
       
   117 				}
       
   118 			if (!tryAgain)
       
   119 				{
       
   120 				User::__DbgMarkEnd(RHeap::EUser, 0);
       
   121 				return error;
       
   122 				}
       
   123 			}
       
   124 		User::__DbgMarkEnd(RHeap::EUser, 0);
       
   125 		if (!tryAgain)
       
   126 			{
       
   127 			break;
       
   128 			}
       
   129 		}
       
   130 	return KErrNone;
       
   131 	}
       
   132 
       
   133 
       
   134 TInt E32Main()
       
   135 	{
       
   136 	return RunServer();
       
   137 	}
       
   138