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