|
1 // Copyright (c) 2005-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 <obexbttransportinfo.h> |
|
17 #include <obex/transport/obexactivereader.h> |
|
18 #include <obex/transport/obexactivewriter.h> |
|
19 #include "ObexBtRfcommTransportController.h" |
|
20 #include "ObexRfcommConnector.h" |
|
21 #include "logger.h" |
|
22 #include "obexbtfaults.h" |
|
23 |
|
24 #ifdef __FLOG_ACTIVE |
|
25 _LIT8(KLogComponent, "RFCOMM"); |
|
26 #endif |
|
27 |
|
28 #ifdef _DEBUG |
|
29 _LIT(KPanicCat, "BtRfcommTc"); |
|
30 #endif |
|
31 |
|
32 /** |
|
33 Constructs a CObexBtRfcommTransportController object. |
|
34 @return Ownership of a new CObexIrdaTtpTransportController object. |
|
35 */ |
|
36 CObexBtRfcommTransportController* CObexBtRfcommTransportController::NewL(TObexTransportInfo& aTransportInfo) |
|
37 { |
|
38 LOG_STATIC_FUNC_ENTRY |
|
39 |
|
40 CObexBtRfcommTransportController* self = new(ELeave) CObexBtRfcommTransportController; |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(aTransportInfo); |
|
43 CleanupStack::Pop(self); |
|
44 return self; |
|
45 } |
|
46 |
|
47 /** Constructor. |
|
48 */ |
|
49 CObexBtRfcommTransportController::CObexBtRfcommTransportController() |
|
50 :CObexTransportControllerBase() |
|
51 { |
|
52 LOG_FUNC |
|
53 } |
|
54 |
|
55 /** 2nd phase construction. |
|
56 */ |
|
57 void CObexBtRfcommTransportController::ConstructL(TObexTransportInfo& aTransportInfo) |
|
58 { |
|
59 LOG_FUNC |
|
60 |
|
61 // It's important in the current implementation to do these these in |
|
62 // roughly this order. We pass the address part of the base class's |
|
63 // transport info by reference to the connector and thence to the |
|
64 // listener. If the user has specified RFCOMM 'passive auto bind' then |
|
65 // just updating the address in the listener will update the transport |
|
66 // controller base's transport info for later query by the user. Using |
|
67 // references saves having to add functions to achieve a manual update of |
|
68 // the data. |
|
69 iTransportInfo = new(ELeave) TObexBtTransportInfo; |
|
70 Mem::Copy(iTransportInfo, &aTransportInfo, sizeof(TObexBtTransportInfo)); |
|
71 TObexBtTransportInfo* btTransportInfo = static_cast<TObexBtTransportInfo*>(iTransportInfo); |
|
72 iConnector = CObexRfcommConnector::NewL(*this, btTransportInfo->iAddr); |
|
73 } |
|
74 |
|
75 /** Destructor. |
|
76 */ |
|
77 CObexBtRfcommTransportController::~CObexBtRfcommTransportController() |
|
78 { |
|
79 LOG_FUNC |
|
80 } |
|
81 |
|
82 /** |
|
83 Gets the socket associated with the connector and asks the socket for its remote name. |
|
84 This can be cast to the appropriate TSockAddr-derived class (TBTSockAddr for BT). |
|
85 */ |
|
86 void CObexBtRfcommTransportController::DoRemoteAddr(TSockAddr& aAddr) |
|
87 { |
|
88 LOG_FUNC |
|
89 LOG(_L8("\taAddr:")); |
|
90 LOGHEXDESC(aAddr); |
|
91 |
|
92 __ASSERT_DEBUG(iConnector, PANIC(KPanicCat, ERfcommTcInternalError)); |
|
93 RSocket& socket = static_cast<CObexRfcommConnector*>(iConnector)->GetSocket(); |
|
94 socket.RemoteName(aAddr); |
|
95 } |
|
96 |
|
97 TBool CObexBtRfcommTransportController::DoIsTransportRestartable() const |
|
98 { |
|
99 LOG_FUNC |
|
100 |
|
101 return ETrue; |
|
102 } |
|
103 |
|
104 TUint16 CObexBtRfcommTransportController::GetReceivePacketDataLimit() |
|
105 { |
|
106 LOG_FUNC |
|
107 |
|
108 // Set initial "software throttle" for packets (how big OBEX says they are) |
|
109 __ASSERT_DEBUG(iTransportInfo, PANIC(KPanicCat, ERfcommTcInternalError)); |
|
110 TUint16 receivePacketDataLimit = iTransportInfo->iReceiveMtu; |
|
111 return receivePacketDataLimit; |
|
112 } |
|
113 |
|
114 /** |
|
115 Creates the reader and writer and constructs the packets |
|
116 @param aInfo Connection info to pass to active reader/writer classes |
|
117 */ |
|
118 void CObexBtRfcommTransportController::NewTransportL(TObexConnectionInfo& aInfo) |
|
119 { |
|
120 LOG_FUNC |
|
121 |
|
122 __ASSERT_DEBUG(iConnector, PANIC(KPanicCat, ERfcommTcInternalError)); |
|
123 RSocket& socket = static_cast<CObexRfcommConnector*>(iConnector)->GetSocket(); |
|
124 iActiveReader = CObexActiveReader::NewL(*this, socket, aInfo); |
|
125 iActiveWriter = CObexActiveWriter::NewL(*this, socket, aInfo); |
|
126 } |
|
127 |
|
128 //From MObexTransportNotify |
|
129 /** |
|
130 Process the received packet |
|
131 @param aPacket Packet to process |
|
132 */ |
|
133 void CObexBtRfcommTransportController::DoProcess(CObexPacket &aPacket) |
|
134 { |
|
135 LOG_FUNC |
|
136 |
|
137 CObexTransportControllerBase::DoProcess(aPacket); |
|
138 } |
|
139 |
|
140 /** |
|
141 Calls base implementation |
|
142 Future proofing against BC breaks |
|
143 @param aError Error code |
|
144 */ |
|
145 void CObexBtRfcommTransportController::DoError(TInt aError) |
|
146 { |
|
147 LOG_FUNC |
|
148 LOG1(_L8("\taError = %d"), aError); |
|
149 |
|
150 CObexTransportControllerBase::DoError(aError); |
|
151 } |
|
152 |
|
153 /** |
|
154 Calls base implementation |
|
155 Future proofing against BC breaks |
|
156 @param aInfo Connection info to pass to active reader/writer classes |
|
157 */ |
|
158 void CObexBtRfcommTransportController::DoTransportUp(TObexConnectionInfo& aInfo) |
|
159 { |
|
160 LOG_FUNC |
|
161 |
|
162 CObexTransportControllerBase::DoTransportUp(aInfo); |
|
163 } |