os/persistentdata/traceservices/tracefw/ulogger/src/outfrwkchans/serial/uloggerserialplugin.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/traceservices/tracefw/ulogger/src/outfrwkchans/serial/uloggerserialplugin.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,214 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <e32std.h>
1.20 +#include <ecom/implementationproxy.h>
1.21 +
1.22 +#include "uloggerserialplugin.h"
1.23 +
1.24 +#if defined(__LIGHTLOGGER_ENABLED)
1.25 +#include "lightlogger.h"
1.26 +#endif
1.27 +
1.28 +namespace Ulogger
1.29 +{
1.30 +
1.31 +#if defined (__WINS__)
1.32 +_LIT(KPddDev, "ECDRV.PDD");
1.33 +#else
1.34 +_LIT(KPddDev, "EUART1");
1.35 +#endif
1.36 +
1.37 +#if defined (__WINS__)
1.38 +_LIT(KLddDev, "ECOMM.LDD");
1.39 +#else
1.40 +_LIT(KLddDev, "ECOMM");
1.41 +#endif
1.42 +
1.43 +//settings for serial output plugin
1.44 +_LIT(KPortNumber, "output_port");
1.45 +
1.46 +/**
1.47 +Creates an instance of CSerialWriter object
1.48 +@return a pointer to the new created CSerialWriter Object
1.49 +@leave KErrNoMemory if no memory
1.50 +*/
1.51 + CSerialWriter* CSerialWriter::NewL()
1.52 + {
1.53 + CSerialWriter *me = new (ELeave) CSerialWriter;
1.54 + CleanupStack::PushL(me);
1.55 + me->ConstructL();
1.56 + CleanupStack::Pop();
1.57 + return me;
1.58 + }
1.59 +
1.60 +/**
1.61 +Public Destructor
1.62 +*/
1.63 +CSerialWriter::~CSerialWriter()
1.64 + {
1.65 + Disconnect();
1.66 + }
1.67 +
1.68 +//default constructor
1.69 +CSerialWriter::CSerialWriter()
1.70 + {
1.71 + }
1.72 +
1.73 +void CSerialWriter::ConstructL()
1.74 + {
1.75 + iReady = EFalse;
1.76 +
1.77 + TInt err = User::LoadPhysicalDevice(KPddDev);
1.78 + if(err!=KErrNone && err!=KErrAlreadyExists)
1.79 + User::Leave(err);
1.80 +
1.81 + err = User::LoadLogicalDevice(KLddDev);
1.82 + if(err!=KErrNone && err!=KErrAlreadyExists)
1.83 + User::Leave(err);
1.84 + }
1.85 +
1.86 +void CSerialWriter::CloseOutputPlugin()
1.87 + {
1.88 + Disconnect();
1.89 + }
1.90 +
1.91 +TInt CSerialWriter::ConfigureOutputPlugin(const RPointerArray<TPluginConfiguration>& aSettings)
1.92 + {
1.93 + TInt i = aSettings.Count();
1.94 + while(i-->0)
1.95 + {
1.96 + TPluginConfiguration* key = aSettings[i];
1.97 +
1.98 + if(key->Key().Compare(KPortNumber) == 0)
1.99 + {
1.100 + TLex lex(key->Value());
1.101 + lex.Val(iPortNum);
1.102 + }
1.103 + }
1.104 +
1.105 + Disconnect();
1.106 + TInt err = Connect();
1.107 + if(err != KErrNone)
1.108 + return err;
1.109 + err = Config();
1.110 +
1.111 + return KErrNone;
1.112 + }
1.113 +
1.114 +TInt CSerialWriter::Connect()
1.115 + {
1.116 + if(!iReady)
1.117 + {
1.118 + TInt err = KErrNone;
1.119 + err = iComm.Open(iPortNum);
1.120 + if(err!=KErrNone)
1.121 + {
1.122 + iReady = EFalse;
1.123 + return err;
1.124 + }
1.125 + else
1.126 + iReady = ETrue;
1.127 + }
1.128 + return KErrNone;
1.129 + }
1.130 +
1.131 +TInt CSerialWriter::Config()
1.132 + {
1.133 + TInt err = KErrNone;
1.134 + if(iReady)
1.135 + {
1.136 + TCommConfig2 cfgBuf;
1.137 + TCommConfigV02& cfg = cfgBuf();
1.138 + iComm.Config(cfgBuf);
1.139 + cfg.iRate = EBps115200;// default EBps9600;
1.140 + cfg.iDataBits = EData8;// default EData8;
1.141 + cfg.iStopBits = EStop1;// default EStop1;
1.142 + cfg.iParity = EParityNone;// default EParityNone;
1.143 + cfg.iHandshake = 0;// default KConfigObeyCTS;
1.144 + cfg.iParityError = KConfigParityErrorFail;
1.145 + cfg.iFifo = EFifoEnable;// default EFifoEnable;
1.146 + cfg.iSpecialRate = 0;// default 0;
1.147 + cfg.iTerminatorCount = 0;// default 0;
1.148 + cfg.iXonChar = 0x11;// default 0x11; // XON
1.149 + cfg.iXoffChar = 0x13;// default 0x13; // XOFF
1.150 + cfg.iParityErrorChar = 0;// default 0;
1.151 + cfg.iSIREnable = ESIRDisable;// default ESIRDisable;
1.152 + cfg.iSIRSettings = 0;// no default
1.153 +
1.154 + err = iComm.SetConfig(cfgBuf);
1.155 + if(err!=KErrNone && err!=KErrInUse)
1.156 + {
1.157 + iReady = EFalse;
1.158 + return(err);
1.159 + }
1.160 + }
1.161 +
1.162 + return err;
1.163 + }
1.164 +
1.165 +TInt CSerialWriter::Disconnect()
1.166 + {
1.167 + if(iReady)
1.168 + {
1.169 + iReady = EFalse;
1.170 + iComm.Close();
1.171 + }
1.172 + return KErrNone;
1.173 + }
1.174 +
1.175 +TInt CSerialWriter::Write(const TDesC8& aData)
1.176 + {
1.177 + TInt err = KErrNone;
1.178 +
1.179 + if(iReady)
1.180 + {
1.181 + TRequestStatus writeStatus;
1.182 + iComm.Write(writeStatus, aData);
1.183 + User::WaitForRequest(writeStatus);
1.184 + err = writeStatus.Int();
1.185 + }
1.186 +
1.187 + return err;
1.188 + }
1.189 +
1.190 +
1.191 +TAny* CSerialWriter::GetInterfaceL(TPluginInterface aInterfaceId)
1.192 + {
1.193 + if(aInterfaceId == MOutputPlugin::iInterfaceId)
1.194 + return static_cast<MOutputPlugin*>(this);
1.195 + else
1.196 + return NULL;
1.197 + }
1.198 +
1.199 +} // namespace
1.200 +
1.201 +
1.202 +//Ecom Implementations
1.203 +// Map the interface implementation UIDs to implementation factory functions
1.204 +const TImplementationProxy ImplementationTable[] =
1.205 + {
1.206 + IMPLEMENTATION_PROXY_ENTRY(0x102836CB, Ulogger::CSerialWriter::NewL)
1.207 + };
1.208 +
1.209 +
1.210 +// Exported proxy for instantiation method resolution.
1.211 +EXPORT_C const TImplementationProxy* ImplementationGroupProxy(
1.212 + TInt& aTableCount)
1.213 + {
1.214 + aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
1.215 + return ImplementationTable;
1.216 + }
1.217 +