|
1 // connector.cpp |
|
2 // |
|
3 // Copyright (c) 2008 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include "connector.h" |
|
14 |
|
15 CConnector* CConnector::NewL(RSocketServ& aSocketServ, RSocket& aSocket, TUint aProtocolFamily, TUint aProtocol, const TSockAddr& aSockAddr, MConnectorObserver& aObserver) |
|
16 { |
|
17 CConnector* self = new(ELeave) CConnector(aSocket, aObserver); |
|
18 CleanupStack::PushL(self); |
|
19 self->ConstructL(aSocketServ, aProtocolFamily, aProtocol, aSockAddr); |
|
20 CleanupStack::Pop(self); |
|
21 return self; |
|
22 } |
|
23 |
|
24 CConnector::~CConnector() |
|
25 { |
|
26 Cancel(); |
|
27 } |
|
28 |
|
29 CConnector::CConnector(RSocket& aSocket, MConnectorObserver& aObserver) |
|
30 : CActive(CActive::EPriorityStandard), iSocket(aSocket), iObserver(aObserver) |
|
31 { |
|
32 CActiveScheduler::Add(this); |
|
33 } |
|
34 |
|
35 void CConnector::ConstructL(RSocketServ& aSocketServ, TUint aProtocolFamily, TUint aProtocol, const TSockAddr& aSockAddr) |
|
36 { |
|
37 User::LeaveIfError(iSocket.Open(aSocketServ, aProtocolFamily, KSockStream, aProtocol)); |
|
38 iSocket.Connect(const_cast<TSockAddr&>(aSockAddr), iStatus); |
|
39 SetActive(); |
|
40 } |
|
41 |
|
42 void CConnector::RunL() |
|
43 { |
|
44 iObserver.ConnectionComplete(iStatus.Int()); |
|
45 } |
|
46 |
|
47 void CConnector::DoCancel() |
|
48 { |
|
49 iSocket.CancelConnect(); |
|
50 } |
|
51 |