|
1 /* |
|
2 * Copyright (c) 2008 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 BTRFCOMMSERVERCONNECTION_H |
|
20 #define BTRFCOMMSERVERCONNECTION_H |
|
21 |
|
22 #include <string> |
|
23 #include <e32base.h> |
|
24 #include <bt_sock.h> |
|
25 #include <btsdp.h> |
|
26 |
|
27 #include "bluetoothfunctionserver.h" |
|
28 #include "bluetoothpusheventlistener.h" |
|
29 #include "monitor.h" |
|
30 #include "servicerecord.h" |
|
31 #include "bturlparams.h" |
|
32 |
|
33 namespace java |
|
34 { |
|
35 namespace bluetooth |
|
36 { |
|
37 class RFCOMMServerConnection: public MBluetoothSocketNotifier |
|
38 { |
|
39 public: |
|
40 OS_IMPORT RFCOMMServerConnection( |
|
41 java::bluetooth::BluetoothFunctionServer* server); |
|
42 OS_IMPORT ~RFCOMMServerConnection(); |
|
43 |
|
44 OS_IMPORT int openServer(bool authorize, bool authenticate, bool encrypt); |
|
45 |
|
46 // To create and initializes the service record. |
|
47 OS_IMPORT int initializeServiceRecord(TInt aChannel, TUUID &aServiceUUID, |
|
48 TDesC8 &aServiceName, bool aIsGOEP); |
|
49 |
|
50 // To create and initializes the service record. |
|
51 OS_IMPORT int initializeServiceRecord(int aChannel, std::wstring aServiceUUID, |
|
52 std::wstring aServiceName, bool aIsGOEP); |
|
53 |
|
54 // Needed in case of push. Accept should not block. |
|
55 OS_IMPORT int asyncAccept( |
|
56 java::bluetooth::BluetoothPushEventListener* aEventListener, |
|
57 BtUrlParams *aBtUrlParams); |
|
58 |
|
59 // Needed in case of push. Restore the service updates from file. |
|
60 OS_IMPORT int restorePersistentRecord(); |
|
61 |
|
62 OS_IMPORT int |
|
63 ServerOpen(TBool authorize, TBool authenticate, TBool encrypt); |
|
64 |
|
65 OS_IMPORT long Accept(); |
|
66 |
|
67 OS_IMPORT int CloseServer(); |
|
68 |
|
69 OS_IMPORT int GetRfListeningChannel(); |
|
70 |
|
71 OS_IMPORT ServiceRecord *getServiceRecordHandle(); |
|
72 |
|
73 public: |
|
74 // Methods from MBluetoothSocketNotifier |
|
75 |
|
76 //Notification of an accept complete event |
|
77 void HandleAcceptCompleteL(TInt err); |
|
78 |
|
79 // Notification of a baseband event |
|
80 void HandleActivateBasebandEventNotifierCompleteL(TInt aErr, |
|
81 TBTBasebandEventNotification &aEventNotification); |
|
82 |
|
83 //Notification of a connection complete event |
|
84 void HandleConnectCompleteL(TInt err); |
|
85 |
|
86 //Notification of a ioctl complete event |
|
87 void HandleIoctlCompleteL(TInt err); |
|
88 |
|
89 //Notification of a receive complete event |
|
90 void HandleReceiveCompleteL(TInt err); |
|
91 |
|
92 //Notification of a send complete event |
|
93 void HandleSendCompleteL(TInt err); |
|
94 |
|
95 //Notification of a shutdown complete event |
|
96 void HandleShutdownCompleteL(TInt err); |
|
97 |
|
98 void avoidFilter(); |
|
99 |
|
100 private: |
|
101 RFCOMMServerConnection(); |
|
102 |
|
103 void ServerOpenL(TBool authorize, TBool authenticate, TBool encrypt); |
|
104 |
|
105 void BindL(TBool authorize, TBool authenticate, TBool encrypt); |
|
106 |
|
107 void ListenL(); |
|
108 |
|
109 ServiceRecord *createServiceRecordL(); |
|
110 |
|
111 long AcceptL(); |
|
112 |
|
113 void DoCancel(); |
|
114 |
|
115 void Close(); |
|
116 |
|
117 int GetRfListeningChannelFs(); |
|
118 |
|
119 bool isConnectionAllowed(TBTSockAddr aBtAddr); |
|
120 |
|
121 private: |
|
122 java::util::Monitor *mAcceptMonitor; |
|
123 |
|
124 int mAcceptStatus; |
|
125 |
|
126 CBluetoothSocket * mAcceptedSocket; |
|
127 |
|
128 // Used in case of Push. |
|
129 bool mAsyncAccept; |
|
130 |
|
131 bool mAvoidFilter; |
|
132 |
|
133 // To notify once client has connected to push server |
|
134 BluetoothPushEventListener* mPushEventListener; |
|
135 |
|
136 // In case of Push, Filter can be used. This parameters used |
|
137 // to filter the incoming connections according to the Filter speicified |
|
138 // while registering for Push. |
|
139 BtUrlParams *mBtUrlParams; |
|
140 private: |
|
141 BluetoothClientConnection *mBtClientConn; |
|
142 java::bluetooth::BluetoothFunctionServer* mServer; |
|
143 |
|
144 // Listening socket |
|
145 CBluetoothSocket* mListenSock; |
|
146 |
|
147 // Socket server handle |
|
148 RSocketServ mSocketServ; |
|
149 |
|
150 // Bluetooth socket address object |
|
151 TBTSockAddr mBtSockAddr; |
|
152 |
|
153 // Listener connection status |
|
154 TBool mIsConnected; |
|
155 |
|
156 // Service Record created for advertising the service |
|
157 ServiceRecord *mServRec; |
|
158 |
|
159 // State of the listener |
|
160 enum TState |
|
161 { |
|
162 ENone = 1, |
|
163 EConnecting, |
|
164 EWaiting, |
|
165 ESending |
|
166 }; |
|
167 |
|
168 TState mState; |
|
169 }; |
|
170 |
|
171 } //end namespace bluetooth |
|
172 } //end namespace java |
|
173 |
|
174 #endif // BTRFCOMMSERVERCONNECTION_H |