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