|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __TRKBTSOCKETCOMMPORT_H__ |
|
20 #define __TRKBTSOCKETCOMMPORT_H__ |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <c32comm.h> |
|
24 #ifdef __UIQ_BUILD__ |
|
25 #include <BTExtNotifiers.h> |
|
26 #include <BtSdp.h> |
|
27 #endif |
|
28 // Extra stuff for RFComm |
|
29 #include <es_sock.h> |
|
30 #include <btdevice.h> |
|
31 #include <bt_sock.h> |
|
32 |
|
33 #include <flogger.h> |
|
34 #include "TrkCommPort.h" |
|
35 #include "TrkConnectionListener.h" |
|
36 #include <btsdp.h> |
|
37 |
|
38 #include <btextnotifiers.h> |
|
39 |
|
40 |
|
41 // |
|
42 // class CTrkBtSocketCommPort |
|
43 // |
|
44 // Defines an interface to a serial type communications port |
|
45 // |
|
46 class TTrkConnData; |
|
47 |
|
48 class MSdpAttributeValueVisitor; |
|
49 class MSdpAgentNotifier; |
|
50 class CTrkBtSocketCommPort : public CTrkCommPort, public MSdpAgentNotifier, public MSdpAttributeValueVisitor |
|
51 { |
|
52 public: |
|
53 |
|
54 static CTrkBtSocketCommPort* NewL(TTrkConnData aTrkConnData, TDes& aErrorMessage, MTrkConnectionListener* aCallback); |
|
55 ~CTrkBtSocketCommPort(); |
|
56 |
|
57 void OpenPortL(); |
|
58 void ClosePort(); |
|
59 |
|
60 void SendDataL(const TDesC8& aData); |
|
61 void Listen(CTrkFramingLayer *aFramingLayer); |
|
62 void StopListening(); |
|
63 |
|
64 void DiscoverPortL(); |
|
65 // stopes the discovery (aborts it and delete variables used for it) |
|
66 void StopDiscovery(); |
|
67 protected: |
|
68 |
|
69 void DoCancel(); |
|
70 void RunL(); |
|
71 |
|
72 private: |
|
73 |
|
74 CTrkBtSocketCommPort(); |
|
75 void ConstructL(TTrkConnData aTrkConnData, TDes& aErrorMessage,MTrkConnectionListener* aCallback); |
|
76 void IssueReadRequest(); |
|
77 void ReportAndLeaveIfErrorL(TInt aError, const TDesC& aDesc); |
|
78 // from MSdpAgentNotifier: |
|
79 void NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount); |
|
80 void AttributeRequestResult(TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue* aAttrValue); |
|
81 void AttributeRequestComplete(TSdpServRecordHandle aHandle, TInt aError); |
|
82 |
|
83 // from MSdpAttributeValueVisitor: |
|
84 void VisitAttributeValueL(CSdpAttrValue &aValue, TSdpElementType aType); // Called for processing of each service attribute. |
|
85 void StartListL(CSdpAttrValueList&); |
|
86 void EndListL(); |
|
87 void ConnectToPortL(); |
|
88 |
|
89 private: |
|
90 |
|
91 TUint iUpdatedPort; |
|
92 TUint iUnitNumber; |
|
93 TUint iRate; |
|
94 |
|
95 RCommServ iServer; |
|
96 //RComm iPort; |
|
97 |
|
98 TBool iServerStarted; |
|
99 TBool iConnected; |
|
100 TBool iListening; |
|
101 |
|
102 TBuf8<MAXMESSAGESIZE> iReceivedChars; |
|
103 TInt iNextReadChar; |
|
104 |
|
105 CTrkFramingLayer* iFramingLayer; |
|
106 |
|
107 // name of the device connector connects |
|
108 THostName iName; |
|
109 // address of the device connector connects |
|
110 TBTDevAddr iAddr; |
|
111 TUUID iCurrUUID; // currently discovered attribute uuid in the service attributes |
|
112 TBool iPortValid; // true if the Port was retrieved |
|
113 TBool iDiscovering; // true if currently discovering the device (if interested on results of listener functions) |
|
114 CSdpSearchPattern* iSearchPattern; // Service discovery search pattern |
|
115 CSdpAgent* iAgent; // Service discovery agent |
|
116 // connecting socket |
|
117 RSocket iSock; |
|
118 |
|
119 // socket server |
|
120 RSocketServ iSocketServ; |
|
121 // length of received data |
|
122 TSockXfrLength iLen; |
|
123 |
|
124 MTrkConnectionListener* iConnectionListener; |
|
125 |
|
126 enum TState |
|
127 { |
|
128 ENone = 1, |
|
129 EConnecting, |
|
130 EWaiting, |
|
131 ESending, |
|
132 EDiscovering, |
|
133 }; |
|
134 TState iState; |
|
135 }; |
|
136 |
|
137 #endif // __TRKBTSOCKETCOMMPORT_H__ |