bluetooth/gavdp/test/tavsrcSock.cpp
branchRCL_3
changeset 24 e9b924a62a66
parent 0 29b1cd4cb562
equal deleted inserted replaced
23:5b153be919d4 24:e9b924a62a66
       
     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 "tavsrcSock.h"
       
    17 #include "tavsrc.h"
       
    18 
       
    19 #ifdef __WINS__
       
    20 static const TSize KReaderConsole(55,10);
       
    21 static const TSize KWriterConsole(55,12);
       
    22 #else
       
    23 static const TSize KReaderConsole(KConsFullScreen,KConsFullScreen);
       
    24 static const TSize KWriterConsole(KConsFullScreen,KConsFullScreen);
       
    25 #endif
       
    26 
       
    27 //
       
    28 // class CActivePacketDropIoctl
       
    29 //
       
    30 CActivePacketDropIoctl* CActivePacketDropIoctl::NewL(CActiveConsole* aLogConsole, RSocketArray aPendingSockets)
       
    31 	{
       
    32 	CActivePacketDropIoctl* self = new (ELeave) CActivePacketDropIoctl(aLogConsole, aPendingSockets);
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 CActivePacketDropIoctl::CActivePacketDropIoctl(CActiveConsole* aLogConsole, RSocketArray aPendingSockets) : CActive(0)
       
    37 	{
       
    38 	iPendingSockets = aPendingSockets;
       
    39 	iLogConsole = aLogConsole;
       
    40 	CActiveScheduler::Add(this);
       
    41 	}
       
    42 
       
    43 CActivePacketDropIoctl::~CActivePacketDropIoctl()
       
    44 	{
       
    45 	}
       
    46 
       
    47 void CActivePacketDropIoctl::DoCancel()
       
    48 	{
       
    49 	Cancel();
       
    50 	}
       
    51 
       
    52 void CActivePacketDropIoctl::Start()
       
    53 	{
       
    54 	iPendingSockets[0].Ioctl(ENotifyAvdtpMediaPacketDropped, iStatus, &iPacketsLostPkgBuf, KSolBtAVDTPMedia);	
       
    55 	SetActive();
       
    56 	}
       
    57 
       
    58 void CActivePacketDropIoctl::RunL()
       
    59 	{
       
    60 	__LOG(_L("\n**Packets Dropped Notification! %d packets lost.\n"), iPacketsLostPkgBuf());		
       
    61 	}
       
    62 
       
    63 //
       
    64 // class CActiveSockReader
       
    65 //
       
    66 CActiveSockReader* CActiveSockReader::NewL(RSocket aSock, TAvdtpTransportSessionType aType)
       
    67 	{
       
    68 	CActiveSockReader* self = new (ELeave) CActiveSockReader(aSock);
       
    69 	CleanupStack::PushL(self);
       
    70 	self->ConstructL(aType);
       
    71 	CleanupStack::Pop(self);
       
    72 	return self;
       
    73 	}
       
    74 
       
    75 CActiveSockReader::CActiveSockReader(RSocket aSock)
       
    76 : CActive(0), iSock(aSock), iBufferDes(NULL, NULL)
       
    77 	{
       
    78 	CActiveScheduler::Add(this);
       
    79 	}
       
    80 	
       
    81 void CActiveSockReader::Start()
       
    82 	{
       
    83 	iSock.Read(iBufferDes,iStatus);
       
    84 	SetActive();
       
    85 	}
       
    86 	
       
    87 void CActiveSockReader::ConstructL(TAvdtpTransportSessionType aType)
       
    88 	{
       
    89 	iType = aType;
       
    90 	switch (aType)
       
    91 		{
       
    92 	case EMedia:
       
    93 		iConsole = Console::NewL(_L("Incoming Sink Data"),KReaderConsole);
       
    94 		break;
       
    95 	case EReporting:
       
    96 		iConsole = Console::NewL(_L("Incoming Reporting Channel Data"),KReaderConsole);
       
    97 		break;
       
    98 	case ERecovery:
       
    99 		iConsole = Console::NewL(_L("Incoming Recovery Channel Data"),KReaderConsole);
       
   100 		break;
       
   101 		}
       
   102 
       
   103 	iBuffer = HBufC8::NewL(40);
       
   104 	iBuffer->Des().SetMax();
       
   105 	iBufferDes.Set(iBuffer->Des());
       
   106 	}
       
   107 
       
   108 CActiveSockReader::~CActiveSockReader()
       
   109 	{
       
   110 	Cancel();
       
   111 	delete iConsole;
       
   112 	iSock.Close();
       
   113 	}
       
   114 	
       
   115 void CActiveSockReader::DoCancel()
       
   116 	{
       
   117 	iSock.CancelAll();
       
   118 	}
       
   119 	
       
   120 void CActiveSockReader::RunL()
       
   121 	{
       
   122 	if (iStatus.Int()==KErrNone)
       
   123 		{
       
   124 		iConsole->Printf(_L("length: [%04d]\n"),iBufferDes.Length());
       
   125 		for (TInt i=0;i<=iBufferDes.Length()-1;i++)
       
   126 			{
       
   127 			iConsole->Printf(_L("%c"),iBufferDes[i]);
       
   128 			}
       
   129 		iConsole->Printf(_L("\n\n"));
       
   130 		iBuffer->Des().SetMax();
       
   131 		iBufferDes.Set(iBuffer->Des());
       
   132 		iSock.Read(iBufferDes,iStatus);
       
   133 		SetActive();
       
   134 		}
       
   135 	else
       
   136 		{
       
   137 		iConsole->Printf(_L("SOCKET ERROR: %d"),iStatus.Int());
       
   138 		}
       
   139 	
       
   140 	}
       
   141 
       
   142 //
       
   143 // class CActiveSockWriter
       
   144 //
       
   145 CActiveSockWriter* CActiveSockWriter::NewL(RSocket aSock,
       
   146 													TAvdtpTransportSessionType aType)
       
   147 	{
       
   148 	CActiveSockWriter* writer = new (ELeave) CActiveSockWriter(aSock);
       
   149 	CleanupStack::PushL(writer);
       
   150 	writer->ConstructL(aType);
       
   151 	CleanupStack::Pop();
       
   152 	return writer;
       
   153 	}
       
   154 
       
   155 CActiveSockWriter::~CActiveSockWriter()
       
   156 	{
       
   157 	delete iSendBuffer;
       
   158 	delete iConsole;
       
   159 	// test for normal shutdown on media socket
       
   160 	TRequestStatus stat;
       
   161 	iSock.Shutdown(RSocket::ENormal, stat);
       
   162 	User::WaitForRequest(stat);
       
   163 	iSock.Close();
       
   164 	}
       
   165 	
       
   166 void CActiveSockWriter::Send()
       
   167 	{
       
   168 	// periodic callback to send from app
       
   169 	if (IsActive())
       
   170 		{
       
   171 		iConsole->Printf(_L("Info: Transport session %d tried to send, but active\n"), iType);
       
   172 		}
       
   173 	else
       
   174 		{
       
   175 		iSock.Write(*iSendBuffer, iStatus);
       
   176 		SetActive();
       
   177 		}
       
   178 	}
       
   179 	
       
   180 CActiveSockWriter::CActiveSockWriter(RSocket aSock)
       
   181 : CActive(-1), iSock(aSock)
       
   182 	{
       
   183 	CActiveScheduler::Add(this);
       
   184 	}
       
   185 
       
   186 void CActiveSockWriter::ConstructL(TAvdtpTransportSessionType aType)
       
   187 	{
       
   188 	//	Writer console to be used in the future if necessary for debugging
       
   189 	//	iConsole = Console::NewL(_L("Writer"), KWriterConsole);
       
   190 	
       
   191 	iSendBuffer = HBufC8::NewL(512);
       
   192 	TPtr8 des = iSendBuffer->Des();
       
   193 	iType = aType;
       
   194 	switch (aType)
       
   195 		{
       
   196 	case EMedia:
       
   197 		des.Copy(_L("Media channel connected!"));
       
   198 		break;
       
   199 	case EReporting:
       
   200 		des.Copy(_L("Reporting channel connected!"));
       
   201 		break;
       
   202 	case ERecovery:
       
   203 		des.Copy(_L("Recovery channel connected!"));
       
   204 		break;
       
   205 	default:
       
   206 		des.Copy(_L("Unknown channel "));
       
   207 		des.AppendNum(aType);
       
   208 		des.Append(_L(" connected!"));
       
   209 		break;
       
   210 		}
       
   211 	}
       
   212 	
       
   213 void CActiveSockWriter::DoCancel()
       
   214 	{
       
   215 	iSock.CancelWrite();
       
   216 	}
       
   217 	
       
   218 void CActiveSockWriter::RunL()
       
   219 	{
       
   220 	//	iConsole->Printf(_L("Info: Transport session %d SENT, result %d"), iType, iStatus.Int());
       
   221 	}