commonuisupport/uikon/test/tmessageserv/messageservsession.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent - Internal Symbian test code  
       
    19 */
       
    20 
       
    21 
       
    22 #include "messageservsession.h"
       
    23 
       
    24 const TInt STOP_SERVER_CODE	= 0xff;
       
    25 
       
    26 
       
    27 /**
       
    28    Constructor - passes client to CSession.
       
    29  */
       
    30 CMessageServSession::CMessageServSession(CMessageServServer * aServer)
       
    31 	: CSession2()//aClient)
       
    32 	{
       
    33 	__DECLARE_NAME(_S("CMessageServSession"));
       
    34 	iMsgSvr=aServer;
       
    35 	}
       
    36 
       
    37 /**
       
    38    Auxiliary function for TestCaseID TPACKAGESTARTER-doTestStepL
       
    39   
       
    40    This method creates a Server session for a client thread aClient.
       
    41   
       
    42  */
       
    43 CMessageServSession* CMessageServSession::NewL(CMessageServServer * aServer)
       
    44 	{
       
    45 	return new(ELeave) CMessageServSession(aServer);
       
    46 	}
       
    47 
       
    48 /**
       
    49    Auxiliary function for TestCaseID TPACKAGESTARTER-doTestStepL
       
    50   
       
    51    This method handles the servicing of client requests to the message server.
       
    52    The message is serviced by calling CMessageServSession::DispatchMessageL()
       
    53    and signals completion of the client request by invoking RMessage::Complete().
       
    54   
       
    55  */
       
    56 void CMessageServSession::ServiceL(const RMessage2& aMessage)
       
    57 	{
       
    58 	TRAPD(err,DispatchMessageL(aMessage));
       
    59 	aMessage.Complete(err);
       
    60 	}
       
    61 
       
    62 /**
       
    63    Auxiliary function for TestCaseID TPACKAGESTARTER-doTestStepL
       
    64   
       
    65    This method services the client requests to the message server.
       
    66    The opcode is checked and does approprate servicing by invoking methods
       
    67    SetFromStringL() and SetErrorFromStringL().
       
    68   
       
    69  */
       
    70 void CMessageServSession::DispatchMessageL(const RMessage2 &aMessage)
       
    71 	{
       
    72 	switch (aMessage.Function())
       
    73         {
       
    74 	case EMessageServSetFromString:
       
    75 		SetFromStringL(aMessage);
       
    76 		return;
       
    77 	case EMessageServSetErrorFromString:
       
    78 		SetErrorFromStringL(aMessage);
       
    79 		return;
       
    80 	case EMessageServStop:
       
    81 		{	
       
    82 			CActiveScheduler::Stop();
       
    83 			
       
    84 			iMsgSvr->iMessageProvider->Message()->RequestForTheMessageOutput(STOP_SERVER_CODE);
       
    85 			return;
       
    86 		}
       
    87 	// requests we don't understand at all are a different thing,
       
    88 	// so panic the client here, this function also completes the message
       
    89 	default:
       
    90 		PanicClient(EBadRequest);
       
    91 		return;
       
    92         }
       
    93 	}
       
    94 
       
    95 /**
       
    96    Auxiliary function for TestCaseID TPACKAGESTARTER-doTestStepL
       
    97   
       
    98    This method services Error message received from the client to the message
       
    99    server. It reads Error message, filename, line number and error code from
       
   100    the message
       
   101   
       
   102  */
       
   103 void CMessageServSession::SetErrorFromStringL(const RMessage2 &aMessage)
       
   104 	{
       
   105 	TInt res;
       
   106 	//const TAny* pD=aMessage.Ptr0();
       
   107 	TInt desLen=aMessage.GetDesLength(0);
       
   108 	HBufC* writeBuf=HBufC::New(desLen);
       
   109 	TPtr initptr = writeBuf->Des();
       
   110 	TRAP(res,aMessage.ReadL(0,initptr));
       
   111 
       
   112 	//const TAny* pD1=aMessage.Ptr1();
       
   113 	TInt desLen1=aMessage.GetDesLength(1);//pD1);
       
   114 	HBufC8* writeBuf1=HBufC8::New(desLen1);
       
   115 	TPtr8 initptr1 = writeBuf1->Des();
       
   116 	TRAP(res,aMessage.ReadL(1,initptr1));
       
   117 
       
   118 
       
   119 	const TInt lineNumber = aMessage.Int2();
       
   120 	const TInt errorCode = aMessage.Int3();
       
   121 
       
   122 	// read the contents of the client pointer into a TPtr.
       
   123 
       
   124 	if (res!=KErrNone)
       
   125 		PanicClient(EBadDescriptor);
       
   126 	
       
   127 	iMsgSvr->iMessageProvider->Message()->iError = errorCode;
       
   128 	iMsgSvr->iMessageProvider->Message()->iLineNumber = lineNumber;
       
   129 	iMsgSvr->iMessageProvider->Message()->iMsg.Copy(initptr);
       
   130 	iMsgSvr->iMessageProvider->Message()->iFileName.Copy(initptr1);
       
   131 
       
   132 	delete writeBuf;
       
   133 	delete writeBuf1;
       
   134 	
       
   135 	iMsgSvr->iMessageProvider->Message()->RequestForTheMessageOutput(errorCode);
       
   136 	}
       
   137 
       
   138 /**
       
   139    Auxiliary function for TestCaseID TPACKAGESTARTER-doTestStepL
       
   140   
       
   141    This method demonstrates reading message from the client address space to
       
   142    the server. It reads filename, line number and descriptor content from
       
   143    the message
       
   144   
       
   145  */
       
   146 void CMessageServSession::SetFromStringL(const RMessage2 &aMessage)
       
   147 	{
       
   148 	TInt res;
       
   149 	//const TAny* pD=aMessage().Ptr0();
       
   150 	TInt desLen=aMessage.GetDesLength(0);
       
   151 	HBufC* writeBuf=HBufC::New(desLen);
       
   152 	TPtr initptr = writeBuf->Des();
       
   153 	TRAP(res,aMessage.ReadL(0,initptr));
       
   154 
       
   155 	//const TAny* pD1=Message().Ptr1();
       
   156 	TInt desLen1=aMessage.GetDesLength(1);
       
   157 	HBufC8* writeBuf1=HBufC8::New(desLen1);
       
   158 	TPtr8 initptr1 = writeBuf1->Des();
       
   159 	TRAP(res,aMessage.ReadL(1,initptr1));
       
   160 
       
   161 
       
   162 	const TInt lineNumber = aMessage.Int2();
       
   163 
       
   164 	// read the contents of the client pointer into a TPtr.
       
   165 
       
   166 	if (res!=KErrNone)
       
   167 		PanicClient(EBadDescriptor);
       
   168 	
       
   169 	iMsgSvr->iMessageProvider->Message()->iLineNumber = lineNumber;
       
   170 	iMsgSvr->iMessageProvider->Message()->iMsg.Copy(initptr);
       
   171 	iMsgSvr->iMessageProvider->Message()->iFileName.Copy(initptr1);
       
   172 
       
   173 	delete writeBuf;
       
   174 	delete writeBuf1;
       
   175 	
       
   176 	iMsgSvr->iMessageProvider->Message()->RequestForTheMessageOutput();
       
   177 	}
       
   178 
       
   179 /**
       
   180    Auxiliary function for TestCaseID TPACKAGESTARTER-doTestStepL
       
   181   
       
   182    This method is used to Panic the client thread
       
   183   
       
   184  */
       
   185 void CMessageServSession::PanicClient(TInt aPanic) const
       
   186 	{
       
   187 	_LIT(KTxtServer,"CountServ server");
       
   188 	User::Panic(KTxtServer,aPanic);
       
   189 	}
       
   190