obex/obexprotocol/obex/test/testobexerrorcodes/TestObexErrorCodesClient.cpp
changeset 57 f6055a57ae18
parent 0 d0791faffa3f
equal deleted inserted replaced
54:4dc88a4ac6f4 57:f6055a57ae18
       
     1 // Copyright (c) 2003-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 <f32file.h>
       
    17 #include "TestObexErrorCodes.h"
       
    18 
       
    19 /**
       
    20  * Static NewL
       
    21  *
       
    22  * @return Base class*
       
    23  */
       
    24 CTestObexErrorCodesClient* CTestObexErrorCodesClient::NewL(CControllerConsoleTest* aOwner)
       
    25 	{
       
    26 	CTestObexErrorCodesClient* self = new(ELeave) CTestObexErrorCodesClient;
       
    27 	CleanupStack::PushL(self);
       
    28 	self->ConstructL(aOwner);
       
    29 	self->StartIrdaClientL();
       
    30 	CleanupStack::Pop( self );
       
    31 
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 
       
    36 
       
    37 
       
    38 /**
       
    39 *
       
    40 * CTestObexErrorCodesClient
       
    41 *
       
    42 */
       
    43 
       
    44 CTestObexErrorCodesClient::CTestObexErrorCodesClient()
       
    45 	{
       
    46 	}
       
    47 
       
    48 /**
       
    49 *
       
    50 * ~CTestObexErrorCodesClient
       
    51 *
       
    52 */
       
    53 
       
    54 CTestObexErrorCodesClient::~CTestObexErrorCodesClient()
       
    55 	{
       
    56 	delete iClient;
       
    57    	}
       
    58 
       
    59 void CTestObexErrorCodesClient::Stop()
       
    60 	{
       
    61 	iOwner->iConsole->Printf(_L("About to Stop the iClient ..\n"));
       
    62 
       
    63 
       
    64 	}
       
    65 
       
    66 
       
    67 void CTestObexErrorCodesClient::Start()
       
    68 	{
       
    69 //Start the test
       
    70 
       
    71 	iClient->Connect();	//should fail with appropriate error code
       
    72 
       
    73 
       
    74 	}
       
    75 
       
    76 
       
    77 
       
    78 
       
    79 void CTestObexErrorCodesClient::StartIrdaClientL()
       
    80 	{
       
    81 
       
    82 	iOwner->iConsole->Printf(_L("About to load the CObexClient...\n"));
       
    83 
       
    84 	TObexIrProtocolInfo aInfo;
       
    85 	aInfo.iTransport     = _L("IrTinyTP");
       
    86 	aInfo.iClassName     = _L8("OBEX");
       
    87 	aInfo.iAttributeName = _L8("IrDA:TinyTP:LsapSel");
       
    88 
       
    89 
       
    90 	iClient  = CObexClientHandler::NewL (this, aInfo);
       
    91 		
       
    92 
       
    93 	iBuf = CBufFlat::NewL(5000);//5000 - what should I put??
       
    94 	iObject  = CObexBufObject::NewL (iBuf);
       
    95 	iOwner->iConsole->Printf(_L("Irda Client loaded Success \n"));
       
    96 
       
    97 	
       
    98 	
       
    99 	}
       
   100 
       
   101 void CTestObexErrorCodesClient::CallBack(TRequestStatus aStatus, TTestProgress aActivity)
       
   102 	{
       
   103 	
       
   104 	//first of all establish what has just happened.
       
   105 	if ( aActivity == EConnecting ) //then it's time for the first PUT
       
   106 		{
       
   107 		iClient->Put();
       
   108 		iErrorCode = ERespContinue;
       
   109 		}
       
   110 	else if (aActivity == EPutting )
       
   111 		{
       
   112 		iOwner->iConsole->Printf(_L("Put Complete with Code %d \n"), aStatus.Int());
       
   113 		if ( iErrorCode < ERespDatabaseLocked )
       
   114 			{
       
   115 			iErrorCode++;
       
   116 			iClient->Put();
       
   117 			}
       
   118 		}
       
   119 
       
   120 	}
       
   121 
       
   122 
       
   123 
       
   124 
       
   125 CObexClientHandler* CObexClientHandler::NewL(CTestObexErrorCodesClient* aOwner,
       
   126 											 TObexProtocolInfo& aObexProtocolInfoPtr)
       
   127 	{
       
   128 	CObexClientHandler* self = new(ELeave) CObexClientHandler;
       
   129 	CleanupStack::PushL(self);
       
   130 	self->ConstructL(aOwner, aObexProtocolInfoPtr);
       
   131 	CleanupStack::Pop( self );
       
   132 
       
   133 	return self;
       
   134 	
       
   135 	}
       
   136 
       
   137 CObexClientHandler::~CObexClientHandler()
       
   138 	{
       
   139 	delete iClient;
       
   140 	}
       
   141 
       
   142 void CObexClientHandler::Connect()
       
   143 	{
       
   144 	if (!IsActive() )
       
   145 		{
       
   146 		iActivity = EConnecting;
       
   147 
       
   148 		iClient->Connect(iStatus);
       
   149 		SetActive();
       
   150 		}
       
   151 	else
       
   152 		iOwner->iOwner->iConsole->Printf(_L("\r\nError: Client handler already active\r\n"));
       
   153 	}
       
   154 
       
   155 void CObexClientHandler::Disconnect()
       
   156 	{
       
   157 	if (!IsActive() )
       
   158 		{
       
   159 		iActivity = EDisconnecting;
       
   160 		iClient->Disconnect(iStatus);
       
   161 		SetActive();
       
   162 		}
       
   163 	else
       
   164 		iOwner->iOwner->iConsole->Printf(_L("\r\nError: Client handler already active\r\n"));
       
   165 
       
   166 	}
       
   167 
       
   168 CObexClientHandler::CObexClientHandler()
       
   169     : CActive(EPriorityNormal)
       
   170 	{
       
   171 	}
       
   172 
       
   173 void CObexClientHandler::ConstructL(CTestObexErrorCodesClient* aOwner,
       
   174 									TObexProtocolInfo& aObexProtocolInfoPtr)
       
   175 	{
       
   176 	iOwner = aOwner;
       
   177 
       
   178     iFileObject = CObexFileObject::NewL();
       
   179 
       
   180 
       
   181 	iClient = CObexClient::NewL(aObexProtocolInfoPtr);
       
   182     CActiveScheduler::Add(this);			// Add to active scheduler
       
   183 	iActivity = EIdle;
       
   184 	}
       
   185 
       
   186 void CObexClientHandler::DoCancel()
       
   187 	{
       
   188 	iClient->Abort();
       
   189 	}
       
   190 
       
   191 void CObexClientHandler::RunL()
       
   192 	{
       
   193 	
       
   194 	iOwner->CallBack(iStatus, iActivity);
       
   195 		
       
   196 	}
       
   197 
       
   198 void CObexClientHandler::Put()
       
   199 	{
       
   200     if(IsActive())
       
   201 		{
       
   202 
       
   203 		iOwner->iOwner->iConsole->Printf(_L("\r\nError: Client handler already active\r\n"));
       
   204 		return;
       
   205 		}
       
   206 
       
   207 	TInt err;
       
   208 
       
   209 	TRAP(err, iFileObject->InitFromFileL (_L("Contacts.vcf")));
       
   210 
       
   211 	if (err != KErrNone)
       
   212 		{
       
   213 		RFs fs;
       
   214 		RFile f;
       
   215 		if ((fs.Connect () != KErrNone) || 
       
   216 			(f.Create (fs, _L("Contacts.vcf"), EFileShareExclusive | EFileWrite) != KErrNone))
       
   217 			iOwner->iOwner->iConsole->Printf(_L("\r\nError reading 'Contacts.vcf'.\r\nI tried to create this file for you, but failed to do that too. Sorry.\r\n\r\n"));
       
   218 		else
       
   219 			{
       
   220 			f.Write (_L8("Test file for sending from EPOC\r\n\r\nLooks like obex is sending OK!!\r\n"));
       
   221 			f.Close ();
       
   222 			iOwner->iOwner->iConsole->Printf(_L("\r\nFile 'Contacts.vcf' did not exist, so I've created one.\r\nPlease try again.\r\n\r\n"));
       
   223 			}
       
   224 		fs.Close ();
       
   225 		}
       
   226 
       
   227 
       
   228 	if( err != KErrNone)
       
   229 		{
       
   230 		iOwner->iOwner->iConsole->Printf(_L("\r\n Couldnt set up object : error %d \r\n"),err);
       
   231 		return;
       
   232 		}
       
   233 
       
   234 	iClient->Put(*iFileObject,iStatus);
       
   235 	SetActive();
       
   236 	iActivity = EPutting;
       
   237 	}