common/tools/ats/smoketest/email/framework/src/T_MsgServer.cpp
changeset 719 d5603c08781b
child 872 17498133d9ad
equal deleted inserted replaced
718:b18be44be852 719:d5603c08781b
       
     1 // Copyright (c) 2006-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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // @file
       
    15 // This is the framework class implementation for the Test Msg Server.
       
    16 // 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 /* User includes */
       
    22 #include "T_MsgServer.h"
       
    23 #include "T_MsgSharedDataBase.h"
       
    24 
       
    25 #include "mobilitytestpropertyvalue.h"
       
    26 #include "mobilitytestpropertymap.h"
       
    27 #include "tmobilitytestpropertymapaccess.h"
       
    28 
       
    29 /* Header files of Test Steps */
       
    30 #include "T_StartUp.h"
       
    31 #include "T_ShutDown.h"
       
    32 #include "T_RecordCurrentTime.h"
       
    33 
       
    34 /* epoc includes */
       
    35 #include <miutset.h>
       
    36 
       
    37 #include <e32const.h>
       
    38 
       
    39 /**
       
    40   Function : CT_MsgServer
       
    41   Description : Constructor
       
    42   @return : N/A
       
    43 */
       
    44 CT_MsgServer::CT_MsgServer()
       
    45 :	CTestServer()
       
    46 ,	iSharedDataBase(NULL)
       
    47 ,	iActiveScheduler(NULL)
       
    48 	{
       
    49 	
       
    50 	//Raise process priority to allow complete event logging.
       
    51 	RProcess me;
       
    52     me.SetPriority(TProcessPriority(450));
       
    53     User::SetPriorityControl(EFalse);
       
    54     
       
    55 	}
       
    56 
       
    57 
       
    58 
       
    59 
       
    60 /**
       
    61   Function : ~CT_MsgServer
       
    62   Description : Destructor
       
    63   @return : N/A
       
    64 */
       
    65 CT_MsgServer::~CT_MsgServer()
       
    66 	{
       
    67 	}
       
    68 
       
    69 
       
    70 
       
    71 /**
       
    72   Function : StartupServerL
       
    73   Description : Creates and installs the active scheduler
       
    74   				Creates an object of the Shared Data class
       
    75   @return : N/A
       
    76 */
       
    77 void CT_MsgServer::StartupServerL()
       
    78 	{
       
    79 	/* Creates the active scheduler, shared data */
       
    80 	if (iActiveScheduler==NULL)
       
    81 		{
       
    82 		/* Installs Active Scheduler */
       
    83 		iActiveScheduler=new(ELeave) CActiveScheduler;
       
    84 		CActiveScheduler::Install(iActiveScheduler);
       
    85 		}
       
    86 
       
    87 	if (iSharedDataBase==NULL)
       
    88 		{
       
    89 		/* Creates the shared data in the re-used thread.*/
       
    90 		iSharedDataBase = NewSharedDataL();
       
    91 		}
       
    92 
       
    93 #ifdef __MOBILITY_TEST_FRAMEWORK
       
    94 	if (iPropertyWatcher==NULL)
       
    95 		{
       
    96 		iPropertyWatcher = CMsgTestPropertyWatcher::NewL(KPropertyCatMsgTestUtilityServer2, EMyPropertyCounter, *this);
       
    97 		}
       
    98 #endif //__MOBILITY_TEST_FRAMEWORK
       
    99 	}
       
   100 
       
   101 
       
   102 
       
   103 /**
       
   104   Function : ShutdownServer
       
   105   Description : Deletes the active scheduler and the created shared data object
       
   106   @return : N/A
       
   107 */
       
   108 void CT_MsgServer::ShutdownServer()
       
   109 	{
       
   110 	if (NULL!=iSharedDataBase)
       
   111 		{
       
   112 		delete iSharedDataBase;
       
   113 		iSharedDataBase=NULL;
       
   114 		}
       
   115 	if (NULL!=iActiveScheduler)
       
   116 		{
       
   117 		delete iActiveScheduler;
       
   118 		iActiveScheduler = NULL;			
       
   119 		}
       
   120 
       
   121 	if (NULL!=iPropertyWatcher)
       
   122 		{
       
   123 		delete iPropertyWatcher;
       
   124 		iPropertyWatcher = NULL;			
       
   125 		}
       
   126 	}
       
   127 
       
   128 
       
   129 /**
       
   130   Function : CreateTestStep
       
   131   Description : This method is run in a seperate thread which is re-used 
       
   132   				when the -SharedData flag is set.
       
   133   @return : A pointer to the CTestStep class
       
   134 */
       
   135 CTestStep* CT_MsgServer::CreateTestStep(const TDesC& aStepName)
       
   136 	{
       
   137 	CTestStep* testStep = NULL;
       
   138 
       
   139 	TRAPD(err,testStep = CreateTestStepL(aStepName));
       
   140 	if(err)
       
   141 		{
       
   142 		ERR_PRINTF1(_L("CT_MsgServer::CreateTestStep() left!"));
       
   143 		}
       
   144 	return testStep;
       
   145 	}
       
   146 
       
   147 
       
   148 
       
   149 /**
       
   150   Function : CreateTestStepL
       
   151   Description : This method creates the startup and shut down test steps
       
   152   @return : A pointer to the CTestStep class
       
   153 */
       
   154 CTestStep* CT_MsgServer::CreateTestStepL(const TDesC& aStepName)
       
   155 	{
       
   156 	CTestStep*	testStep = NULL;
       
   157 
       
   158 	/* This must be called as the first test step */
       
   159 	if(aStepName == KStartUp)					
       
   160 		{
       
   161 		StartupServerL();
       
   162 		testStep = new(ELeave) CT_MsgStartUp();
       
   163 		}
       
   164 	/* This must be called as the last test step */
       
   165 	else if(aStepName == KShutDown)				
       
   166 		{
       
   167 		ShutdownServer();
       
   168 		testStep = new(ELeave) CT_MsgShutDown();
       
   169 		}
       
   170 	else if(aStepName == KRecordCurrentTime)
       
   171 		{
       
   172 		testStep = new(ELeave) CT_MsgRecordCurrentTime();	
       
   173 		}
       
   174 
       
   175 	else
       
   176 		{
       
   177 		ERR_PRINTF1(_L("CT_MsgServer::CreateTestStep() - Step not found"));	
       
   178 		}
       
   179 	return testStep;
       
   180 	}
       
   181 
       
   182 
       
   183 #ifdef __MOBILITY_TEST_FRAMEWORK
       
   184 void CT_MsgServer::HandleEventL(RProperty& aProperty, TUint /*aKey*/)
       
   185 #else //__MOBILITY_TEST_FRAMEWORK
       
   186 void CT_MsgServer::HandleEventL(RProperty& /*aProperty*/, TUint /*aKey*/)
       
   187 #endif //__MOBILITY_TEST_FRAMEWORK
       
   188 	{
       
   189 #ifdef __MOBILITY_TEST_FRAMEWORK
       
   190 
       
   191 	TInt propertyVal = 0;
       
   192 	User::LeaveIfError(aProperty.Get(propertyVal));
       
   193 
       
   194 	const TDesC& name = Name(); //Server name.
       
   195 
       
   196 
       
   197 	const TMsgTestPropertyMapEntry* propertyMap = TMobilityTestPropertyMapAccess::Get(propertyVal);
       
   198 	if(propertyMap == NULL)
       
   199 		{
       
   200 		ERR_PRINTF1(_L("CT_MsgServer::HandleEventL() - Event not found"));
       
   201 		}
       
   202 	else
       
   203 		{
       
   204 		TBufC8<80> buf8((const unsigned char*)(propertyMap->name));
       
   205 		TBuf<80> buf;
       
   206 		buf.Copy(buf8);
       
   207 		INFO_PRINTF4(_L("%S EVENT [%d %S]"), &name, propertyVal, &buf);
       
   208 		}
       
   209 #endif //__MOBILITY_TEST_FRAMEWORK
       
   210 	}