windowing/windowserver/debuglog/DEBLOGSR.CPP
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1996-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 // code for the serial device derived class 
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "../SERVER/w32cmd.h"
       
    19 #include "DEBLOGSR.H"
       
    20 
       
    21 /*#if defined(__WINS__)
       
    22 #pragma data_seg(".E32_UID")
       
    23 __WINS_UID(0, KWservLoggingDllUidValue, 0)
       
    24 #pragma data_seg()
       
    25 #endif*/
       
    26 
       
    27 //#define DEBUGLOG_SHOW_TRACE
       
    28 
       
    29 #ifdef DEBUGLOG_SHOW_TRACE
       
    30 void ShowTrace(TRefByValue<const TDesC> aFmt,...)
       
    31 	{
       
    32 	RDebug::Print(aFmt);
       
    33 	}
       
    34 #else
       
    35 void ShowTrace(TRefByValue<const TDesC> /*aFmt*/,...)
       
    36 	{
       
    37 	}
       
    38 #endif
       
    39 
       
    40 
       
    41 
       
    42 EXPORT_C CDebugLogBase *CreateDebugLog(TBool aIsFirst, TDesC &aParams)
       
    43 	{
       
    44 	CDebugLogSerial *device=new(ELeave) CDebugLogSerial();
       
    45 	CDebugLog *log=NULL;
       
    46 	ShowTrace(_L("!!$L Allocating Log"));
       
    47 	TRAPD(err,log=new(ELeave) CDebugLog(device));
       
    48 	if (err!=KErrNone)
       
    49 		{
       
    50 		delete device;
       
    51 		User::Leave(err);
       
    52 		}
       
    53 	ShowTrace(_L("!!$L Initialising Log"));
       
    54 	TRAP(err,log->ConstructL(aIsFirst, aParams));
       
    55 	if (err!=KErrNone)
       
    56 		{
       
    57 		delete log;
       
    58 		User::Leave(err);
       
    59 		}
       
    60 	return(log);
       
    61 	}
       
    62 
       
    63 
       
    64 CDebugLogSerial::CDebugLogSerial()
       
    65 	{
       
    66 	__DECLARE_NAME(_S("CDebugLogSerial"));
       
    67 	}
       
    68 
       
    69 CDebugLogSerial::~CDebugLogSerial()
       
    70 	{
       
    71 	iSerialPort.Close();
       
    72 	}
       
    73 
       
    74 void CDebugLogSerial::ConstructL(TBool , TDesC &)
       
    75 	{
       
    76 #if defined(__EPOC32__)
       
    77 	ShowTrace(_L("!!$L Getting Dev1"));
       
    78 	User::LeaveIfError(User::LoadPhysicalDevice(_L("EUART1")));
       
    79 #else
       
    80 	User::LeaveIfError(User::LoadPhysicalDevice(_L("ECDRV")));
       
    81 #endif
       
    82 	ShowTrace(_L("!!$L Getting Dev2"));
       
    83 	User::LeaveIfError(User::LoadLogicalDevice(_L("ECOMM")));
       
    84 	iSerialPort.Open(0);
       
    85 //
       
    86 	TCommConfig cBuf;
       
    87 	TCommConfigV01& c=cBuf();
       
    88 	iSerialPort.Config(cBuf);
       
    89 //	c.iRate=EBps19200;
       
    90 	c.iRate=EBps115200;
       
    91 	c.iHandshake=0;
       
    92 	ShowTrace(_L("!!$L Configering Port"));
       
    93 	User::LeaveIfError(iSerialPort.SetConfig(cBuf));
       
    94 	}
       
    95 
       
    96 void CDebugLogSerial::WriteToLogL(const TDesC &aDes, const TDesC &aDes2)
       
    97 	{
       
    98 	TBuf<LogTBufSize+2> buf(aDes);
       
    99 	buf.Append(TPtrC(_S("\r\n")));
       
   100 	TRequestStatus stat;
       
   101 	iSerialPort.Write(stat,TPtrC8((TUint8 *)buf.Ptr(),buf.Size()));
       
   102 	User::WaitForRequest(stat);
       
   103 	User::LeaveIfError(stat.Int());
       
   104 //
       
   105 	iSerialPort.Write(stat,TPtrC8((TUint8 *)aDes2.Ptr(),aDes2.Size()));
       
   106 	User::WaitForRequest(stat);
       
   107 	User::LeaveIfError(stat.Int());
       
   108 	}
       
   109 
       
   110 void CDebugLogSerial::WriteToLog8L(const TDesC8 &aDes, const TDesC8 &aDes2)
       
   111 	{
       
   112 	TBuf8<LogTBufSize+2> buf(aDes);
       
   113 	buf.Append(TPtrC(_S("\r\n")));
       
   114 	TRequestStatus stat;
       
   115 	iSerialPort.Write(stat,buf);
       
   116 	User::WaitForRequest(stat);
       
   117 	User::LeaveIfError(stat.Int());
       
   118 //
       
   119 	iSerialPort.Write(stat,aDes2);
       
   120 	User::WaitForRequest(stat);
       
   121 	User::LeaveIfError(stat.Int());
       
   122 	}
       
   123