traceservices/tracefw/ulogger/src/outfrwkchans/serial/uloggerserialplugin.cpp
changeset 0 08ec8eefde2f
child 23 26645d81f48d
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2007-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 #include <e32std.h>
       
    17 #include <ecom/implementationproxy.h>
       
    18 #include "uloggerserialplugin.h"
       
    19 
       
    20 #if defined(__LIGHTLOGGER_ENABLED)
       
    21 #include "lightlogger.h" 
       
    22 #endif
       
    23 
       
    24 namespace Ulogger
       
    25 {
       
    26 
       
    27 #if defined (__WINS__)
       
    28 _LIT(KPddDev, "ECDRV.PDD");
       
    29 #else
       
    30 _LIT(KPddDev, "EUART1");
       
    31 #endif
       
    32 
       
    33 #if defined (__WINS__)
       
    34 _LIT(KLddDev, "ECOMM.LDD");
       
    35 #else
       
    36 _LIT(KLddDev, "ECOMM");
       
    37 #endif
       
    38 
       
    39 //settings for serial output plugin
       
    40 _LIT(KPortNumber, "output_port");
       
    41 
       
    42 /**
       
    43 Creates an instance of CSerialWriter object
       
    44 @return a pointer to the new created CSerialWriter Object
       
    45 @leave KErrNoMemory if no memory
       
    46 */
       
    47  CSerialWriter* CSerialWriter::NewL()
       
    48 	{
       
    49 	CSerialWriter *me = new (ELeave) CSerialWriter;
       
    50 	CleanupStack::PushL(me);
       
    51 	me->ConstructL();
       
    52 	CleanupStack::Pop();
       
    53 	return me;
       
    54 	}
       
    55 
       
    56 /**
       
    57 Public Destructor
       
    58 */
       
    59 CSerialWriter::~CSerialWriter()
       
    60 	{
       
    61     Disconnect();
       
    62 	}
       
    63 
       
    64 //default constructor
       
    65 CSerialWriter::CSerialWriter()
       
    66 	{
       
    67 	}
       
    68 
       
    69 void CSerialWriter::ConstructL()
       
    70 	{
       
    71 	iReady = EFalse;
       
    72 	
       
    73     TInt err = User::LoadPhysicalDevice(KPddDev);
       
    74     if(err!=KErrNone && err!=KErrAlreadyExists)
       
    75         User::Leave(err);
       
    76 
       
    77     err = User::LoadLogicalDevice(KLddDev);
       
    78     if(err!=KErrNone && err!=KErrAlreadyExists)
       
    79         User::Leave(err);
       
    80  	}
       
    81 
       
    82 void CSerialWriter::CloseOutputPlugin()
       
    83 	{
       
    84     Disconnect();
       
    85 	}
       
    86 
       
    87 TInt CSerialWriter::ConfigureOutputPlugin(const RPointerArray<TPluginConfiguration>& aSettings)
       
    88 	{
       
    89 	TInt i = aSettings.Count();
       
    90 	while(i-->0)
       
    91 		{
       
    92 		TPluginConfiguration* key = aSettings[i];
       
    93 	    
       
    94 		if(key->Key().Compare(KPortNumber) == 0)
       
    95 			{
       
    96 			TLex lex(key->Value());
       
    97 			lex.Val(iPortNum);
       
    98 			}
       
    99 		}
       
   100 
       
   101 	Disconnect();
       
   102 	TInt err = Connect();
       
   103 	if(err != KErrNone)
       
   104 		return err;
       
   105 	err = Config();
       
   106 
       
   107 	return KErrNone;
       
   108 	}
       
   109 
       
   110 TInt CSerialWriter::Connect()
       
   111     {
       
   112     if(!iReady)
       
   113         {
       
   114         TInt err = KErrNone;
       
   115         err = iComm.Open(iPortNum);
       
   116         if(err!=KErrNone)
       
   117         	{
       
   118        		iReady = EFalse;
       
   119             return err;
       
   120         	}
       
   121         	else
       
   122 		        iReady = ETrue;
       
   123         }
       
   124     return KErrNone;
       
   125     }
       
   126 
       
   127 TInt CSerialWriter::Config()
       
   128     {
       
   129     TInt err = KErrNone;
       
   130     if(iReady)
       
   131         {
       
   132         TCommConfig2 cfgBuf;
       
   133         TCommConfigV02& cfg = cfgBuf();
       
   134         iComm.Config(cfgBuf);
       
   135         cfg.iRate = EBps115200;// default EBps9600;
       
   136         cfg.iDataBits = EData8;// default EData8;
       
   137         cfg.iStopBits = EStop1;// default EStop1;
       
   138         cfg.iParity = EParityNone;// default EParityNone;
       
   139         cfg.iHandshake = 0;// default KConfigObeyCTS;
       
   140         cfg.iParityError = KConfigParityErrorFail;
       
   141         cfg.iFifo = EFifoEnable;// default EFifoEnable;
       
   142         cfg.iSpecialRate = 0;// default 0;
       
   143         cfg.iTerminatorCount = 0;// default 0;
       
   144         cfg.iXonChar = 0x11;// default 0x11; // XON
       
   145         cfg.iXoffChar = 0x13;// default 0x13; // XOFF
       
   146         cfg.iParityErrorChar = 0;// default 0;
       
   147         cfg.iSIREnable = ESIRDisable;// default ESIRDisable;
       
   148         cfg.iSIRSettings = 0;// no default
       
   149         
       
   150         err = iComm.SetConfig(cfgBuf);
       
   151         if(err!=KErrNone && err!=KErrInUse)
       
   152             {
       
   153             iReady = EFalse;
       
   154             return(err);
       
   155             }
       
   156         }
       
   157     
       
   158     return err;
       
   159     }
       
   160 
       
   161 TInt CSerialWriter::Disconnect()
       
   162     {
       
   163     if(iReady)
       
   164         {
       
   165 	    iReady = EFalse;
       
   166         iComm.Close();
       
   167         }
       
   168     return KErrNone;
       
   169     }
       
   170 
       
   171 TInt CSerialWriter::Write(const TDesC8& aData)
       
   172 	{
       
   173 	TInt err = KErrNone;
       
   174 	
       
   175 	if(iReady)
       
   176 		{
       
   177 		TRequestStatus writeStatus;
       
   178 	    iComm.Write(writeStatus, aData);
       
   179     	User::WaitForRequest(writeStatus);
       
   180     	err = writeStatus.Int();  	
       
   181 		}
       
   182 
       
   183    	return err;
       
   184 	}
       
   185 
       
   186 
       
   187 TAny* CSerialWriter::GetInterfaceL(TPluginInterface aInterfaceId)
       
   188 	{
       
   189 	if(aInterfaceId == MOutputPlugin::iInterfaceId)
       
   190 		return static_cast<MOutputPlugin*>(this);
       
   191 	else
       
   192 		return NULL;
       
   193 	}
       
   194 
       
   195 } // namespace
       
   196 
       
   197 
       
   198 //Ecom Implementations
       
   199 // Map the interface implementation UIDs to implementation factory functions
       
   200 const TImplementationProxy ImplementationTable[] =
       
   201     {
       
   202     IMPLEMENTATION_PROXY_ENTRY(0x102836CB,  Ulogger::CSerialWriter::NewL)
       
   203     };
       
   204 
       
   205 
       
   206 // Exported proxy for instantiation method resolution.
       
   207 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(
       
   208     TInt& aTableCount)
       
   209     {
       
   210     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   211     return ImplementationTable;
       
   212     }
       
   213