mmtestenv/mmtestfw/Source/TestFrameworkClient/Log.cpp
branchRCL_3
changeset 12 b74061f7f3d2
parent 0 40261b775718
equal deleted inserted replaced
11:d5f04de580b7 12:b74061f7f3d2
    42 
    42 
    43 _LIT(KResultKnownFailure, "<font size=4 color=008080>"); //A new TVerdict for a known failed test
    43 _LIT(KResultKnownFailure, "<font size=4 color=008080>"); //A new TVerdict for a known failed test
    44 
    44 
    45 // logging macro used only for verdicts - not for external use
    45 // logging macro used only for verdicts - not for external use
    46 #define VER_PRINTF(r1, r2, r3)		LogExtra(__FILE8__, __LINE__, ESevrVer, _L("%S%S%S\n"), (r1), (r2), (r3)) 
    46 #define VER_PRINTF(r1, r2, r3)		LogExtra(__FILE8__, __LINE__, ESevrVer, _L("%S%S%S\n"), (r1), (r2), (r3)) 
    47 
       
    48 /**
       
    49  *
       
    50  * Global : start a server
       
    51  * NOTE. Function is global static as only one server will ever run at any time
       
    52  * (there may be multiple client sessions)
       
    53  *
       
    54  * @return	"TInt"
       
    55  *			Error code (KErrNone if successful)
       
    56  *
       
    57  * @xxxx
       
    58  *
       
    59  */
       
    60 GLDEF_C TInt StartServer()
       
    61 // Start the server process/thread which lives in an (EPOC)EXE object
       
    62 	{
       
    63 	const TUidType serverUid(KNullUid, KNullUid, KTestFrameworkServerUid3);
       
    64 
       
    65 
       
    66 // EPOC is easy, we just create a new server process. Simultaneous launching
       
    67 // of two such processes should be detected when the second one attempts to
       
    68 // create the server object, failing with KErrAlreadyExists.
       
    69 
       
    70 	RProcess server;
       
    71 	TInt r = server.Create(KTestFrameworkServerImg, KNullDesC, serverUid);
       
    72 
       
    73 	if (r != KErrNone)
       
    74 		return r;
       
    75 
       
    76 	
       
    77 	TRequestStatus rendezvous;
       
    78 	server.Rendezvous(rendezvous);
       
    79 
       
    80 	if (rendezvous!=KRequestPending)
       
    81 		{
       
    82 		server.Kill(0);
       
    83 		}
       
    84 	else
       
    85 		{
       
    86 		server.Resume();
       
    87 		}
       
    88 
       
    89 
       
    90 	User::WaitForRequest(rendezvous);		// wait for start or death
       
    91 
       
    92 	// we can't use the 'exit reason' if the server panicked as this
       
    93 	// is the panic 'reason' and may be '0' which cannot be distinguished
       
    94 	// from KErrNone
       
    95 	if (rendezvous!=KErrNone)
       
    96 		{
       
    97 		server.Close();
       
    98 		}
       
    99 
       
   100 	// server started (at last). Cancel and consume the death-notification
       
   101 	// before reporting success
       
   102 	return rendezvous.Int();
       
   103 	}
       
   104 
       
   105 /**
       
   106  *
       
   107  * Constructor for RTestFrameworkClientSession
       
   108  *
       
   109  * @xxxx
       
   110  *
       
   111  */
       
   112 RTestFrameworkClientSession::RTestFrameworkClientSession()
       
   113 	{
       
   114 	}
       
   115 
       
   116 /**
       
   117  *
       
   118  * Client session : connect to server.
       
   119  * Will start a new server session if no server exists
       
   120  *
       
   121  * @return	"TInt"
       
   122  *			Error code (KErrNone if connect successful)
       
   123  *
       
   124  * @xxxx
       
   125  *
       
   126  */
       
   127 TInt RTestFrameworkClientSession::Connect()
       
   128 	{
       
   129 	// NOTE : this loop is ugly and can probably be rewritten to be more graceful
       
   130 	const TInt KNumRetries = 2;
       
   131 
       
   132 	TInt retry = KNumRetries;
       
   133 	for (;;)
       
   134 		{
       
   135 		TInt r = CreateSession(KTestFrameworkServerName, TVersion(KTestFrameworkServerMajorVersionNumber,
       
   136 																  KTestFrameworkServerMinorVersionNumber,
       
   137 																  KTestFrameworkServerBuildVersionNumber));
       
   138 		if (r == KErrNone)
       
   139 			{
       
   140 #ifdef __IPC_V2_PRESENT__
       
   141 			r = ShareAuto();
       
   142 #else
       
   143 			r = Share(RSessionBase::EAutoAttach);
       
   144 #endif
       
   145 			if (r!=KErrNone)
       
   146 				Close();
       
   147 			return r;
       
   148 			}
       
   149 		if (r != KErrNotFound && r != KErrServerTerminated)
       
   150 			{
       
   151 			return r;
       
   152 			}
       
   153 		if (--retry == 0)
       
   154 			return r;
       
   155 		r = StartServer();
       
   156 		if (r != KErrNone && r != KErrAlreadyExists)
       
   157 			return r;
       
   158 		}
       
   159 	}
       
   160 
       
   161 /**
       
   162  *
       
   163  * Request creation of an input window.
       
   164  * NOTE. For initialisation of input console only - unlikely to
       
   165  * be required by user
       
   166  *
       
   167  * @param	"TRectBuf& aAllocatedWindow"
       
   168  *			Window dimensions
       
   169  *
       
   170  * @param	"TRequestStatus& aReqStat"
       
   171  *			Request status
       
   172  *
       
   173  * @xxxx
       
   174  *
       
   175  */
       
   176 void RTestFrameworkClientSession::CreateInputWindow(TRectBuf& aAllocatedWindow, TRequestStatus& aReqStat)
       
   177 	{
       
   178 	SendReceiveResult(ECreateInputWindow, aAllocatedWindow, aReqStat);
       
   179 	}
       
   180 
       
   181 /**
       
   182  *
       
   183  * Request window change notifications
       
   184  * NOTE. For initialisation of input console only - unlikely to
       
   185  * be required by user
       
   186  *
       
   187  * @param	"TRectBuf& aNewWindow"
       
   188  *			New window dimensions
       
   189  *
       
   190  * @param	"TRequestStatus& aReqStat"
       
   191  *			Request status
       
   192  *
       
   193  * @xxxx
       
   194  *
       
   195  */
       
   196 void RTestFrameworkClientSession::NotifyIfWindowChange(TRectBuf& aNewWindow, TRequestStatus& aReqStat)
       
   197 	{
       
   198 	SendReceiveResult(ENotifyIfWindowChange, aNewWindow, aReqStat);
       
   199 	}
       
   200 
       
   201 /**
       
   202  *
       
   203  * Cancel window change notifications
       
   204  * NOTE. For initialisation of input console only - unlikely to
       
   205  * be required by user
       
   206  *
       
   207  * @return	"TInt"
       
   208  *			SendReceive error code
       
   209  *
       
   210  * @xxxx
       
   211  *
       
   212  */
       
   213 TInt RTestFrameworkClientSession::CancelNotifyIfWindowChange()
       
   214 	{
       
   215 	return SendReceive(ECancelNotifyIfWindowChange);
       
   216 	}
       
   217 
       
   218 
       
   219 /**
       
   220  *
       
   221  * Open a log server session
       
   222  *
       
   223  * @param	"const TDesC& aLogName"
       
   224  *			The log name
       
   225  *
       
   226  * @param	"TInt aLogMode"
       
   227  *			The log mode (a bitmask of TTestFrameworkLogMode)
       
   228  *
       
   229  * @xxxx
       
   230  *
       
   231  */
       
   232 void RTestFrameworkClientSession::OpenLog(const TDesC& aLogName, TInt aLogMode)
       
   233 	{
       
   234 	(void) SendReceive(EOpenLog, aLogName, aLogMode);
       
   235 	}
       
   236 
       
   237 /**
       
   238  *
       
   239  * Write message string to log server session
       
   240  *
       
   241  * @param	"const TDesC& aMsg"
       
   242  *			The message string
       
   243  *
       
   244  * @param	"TInt aLogMode"
       
   245  *			The log mode (a bitmask of TTestFrameworkLogMode)
       
   246  *
       
   247  * @xxxx
       
   248  *
       
   249  */
       
   250 void RTestFrameworkClientSession::WriteLog(const TDesC& aMsg, TInt aLogMode)
       
   251 	{
       
   252 	(void) SendReceive(EWriteLog, aMsg, aLogMode);
       
   253 	}
       
   254 
       
   255 /**
       
   256  *
       
   257  * Send close log message to server
       
   258  *
       
   259  * @xxxx
       
   260  *
       
   261  */
       
   262 void RTestFrameworkClientSession::CloseLog()
       
   263 	{
       
   264 	SendReceive(ECloseLog);
       
   265 	}
       
   266 
       
   267 /**
       
   268  *
       
   269  * Retrieve log status from server
       
   270  *
       
   271  * @return	"TInt"
       
   272  *			The log status (a bitmask of TTestFrameworkLogMode)
       
   273  *
       
   274  * @xxxx
       
   275  *
       
   276  */
       
   277 TInt RTestFrameworkClientSession::LogStatus()
       
   278 	{
       
   279 	TInt res = 0;
       
   280 	TPckgBuf<TInt> pckg;
       
   281 	TInt r = SendReceiveResult(ELogStatus, pckg);
       
   282 	if (r != KErrNone)
       
   283 	{
       
   284 		// RTestFrameworkClientSession does not log - 
       
   285 		// we can however return 0 to indicate an error (no outputs)
       
   286 		res = 0;
       
   287 	}
       
   288 	else
       
   289 		res = pckg();
       
   290 	return res;
       
   291 	}
       
   292 
    47 
   293 /**
    48 /**
   294  *
    49  *
   295  * Static constructor for CLog.
    50  * Static constructor for CLog.
   296  *
    51  *