00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef BLUETOOTHDISCOVERY_SYMBIAN_H
00031 #define BLUETOOTHDISCOVERY_SYMBIAN_H
00032
00033
00034 #include <e32base.h>
00035 #include <es_sock.h>
00036 #include <btdevice.h>
00037 #include <bt_sock.h>
00038 #include <btsdp.h>
00039 #include <btmanclient.h>
00040
00041 #include "common.h"
00042 #include "devicediscoverer.h"
00043 #include "servicediscoverer.h"
00044 #include "serviceadvertiser.h"
00045 #include "listener.h"
00046 #include "connector.h"
00047 #include "bluetoothdiscovery.h"
00048
00049
00050 const TInt KMaxConnectedDevices=7;
00051
00052
00053 const TInt KMsgLength = 384;
00054
00055
00056 const TInt KEighty = 80;
00057 const TInt KThirty = 30;
00058 const TInt KTwenty = 20;
00059 const TInt KTwelve = 12;
00060 const TInt KForty = 40;
00061
00062
00063 _LIT(KDeviceWithNoName,"*Jane Doe*");
00064 _LIT(KNoServiceFound,"No services found!\n");
00065 _LIT(KNewLine,"\n");
00066 _LIT(KServiceFound,"Found service on:\n");
00067 _LIT(KNoDevFound,"\nNo devices found!");
00068 _LIT(KDevices," devices.");
00069 _LIT(KFoundTxt,"Found ");
00070 _LIT(KSecTxt," s.");
00071 _LIT(KTimeTxt,"time ");
00072 _LIT(KFormatStr,"< %S: %S\n");
00073 _LIT(KDisconMsg,"Disconnected!\nSlave stopped.\n");
00074 _LIT(KDeviceDisconMsg,"%S disconnected!\n");
00075 _LIT(KConnMsg,"Connected!\n");
00076 _LIT(KFormatStr1,"< %S\n");
00077 _LIT(KFormatStr2,"> %S: %S\n");
00078 _LIT(KFormatStr3,"> %S\n");
00079 _LIT(KMessage,"message");
00080 _LIT(KNoConns,"No connections!");
00081 _LIT(KConnDevicesTxt,"Connected devices:\n");
00082 _LIT(KConnectingTxt, "Connecting...\n");
00083 _LIT(KDisconnDevicesTxt, "Devices disconnected\n");
00084 _LIT(KSlaveInitCompTxt,"\nSlave init complete!\nWaiting for connection.");
00085 _LIT(KListeningTxt,"\nListening channel %d");
00086 _LIT(KSlaveInitTxt,"Slave init..");
00087 _LIT(KDiscServicesTxt,"Discovering services,\nplease wait...\n");
00088 _LIT(KDiscDevicesTxt,"Discover devices,\nplease wait...\n");
00089
00090 _LIT(KServiceDiscoveryError, "Serv disco error:");
00091 _LIT(KTurningOn, "Turning bt on");
00092
00093
00094
00095 class CDeviceDiscoverer;
00096 class CServiceAdvertiser;
00097 class CServiceDiscoverer;
00098 class CListener;
00099 class CConnector;
00100
00101
00102
00103
00108 class BluetoothDiscoveryPrivate : public CBase,
00109 public MListenerObserver,
00110 public MConnectorObserver,
00111 public MDeviceDiscoObserver,
00112 public MServiceDiscoObserver
00113 {
00114 public:
00115 enum TBluetoothDiscoveryMode{
00116 EStopDeviceDiscovery = 0,
00117 EDeviceDiscoveryComplete,
00118 EHasDevices,
00119 EHasServices,
00120 EHasConnections,
00121 EStopSlave,
00122 ESendMessage
00123 };
00124
00131 static BluetoothDiscoveryPrivate* NewL(BluetoothDiscovery *aPublicAPI = 0);
00132
00137 static BluetoothDiscoveryPrivate* NewLC(BluetoothDiscovery *aPublicAPI);
00138
00144 ~BluetoothDiscoveryPrivate();
00145
00146 public:
00147
00154 void DiscoverDevicesL();
00155
00161 void DiscoverServicesL();
00162
00170 void StartSlaveL();
00171
00172 void StopSlaveL();
00173
00180 void SendMessageL();
00181
00188 void ConnectDevicesL();
00189
00195 void DisconnectDevices();
00196
00202 void ShowConnectedDevicesL();
00203
00211 void HandleListenerDataReceivedL(const TDesC& aData);
00212
00221 void HandleConnectorDataReceivedL(THostName aName, const TDesC& aData);
00222 void HandleConnectorErrorL(THostName aName, TInt aError);
00229 void HandleListenerConnectedL();
00230
00237 void HandleListenerDisconnectedL();
00238
00245 void HandleDeviceDiscoveryComplete(TInt aError);
00246
00247
00248
00249
00250 void DeviceDiscovered(const TDeviceData &aDevice);
00251
00258 void HandleServiceDiscoveryCompleteL();
00259
00265 void ReportServiceDiscoveryErrorL(TInt aError);
00266
00272 TBool HasConnections();
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 void TurnBtOnL();
00284
00291 TBool IsDiscoveryActive();
00292
00299 void StopDiscovery();
00300
00301 private:
00302
00312 void ChangeMenuOptions();
00313
00314
00315 private:
00316
00321 void ConstructL();
00322
00328 BluetoothDiscoveryPrivate(BluetoothDiscovery* );
00329
00330
00331 public:
00332
00333
00334 CListener* iListener;
00335
00336 CDeviceDiscoverer* iDeviceDiscoverer;
00337
00338 CServiceAdvertiser* iServiceAdvertiser;
00339
00340 CServiceDiscoverer* iServiceDiscoverer;
00341
00342 TBool iIsSlave;
00343
00344 TBool iIsMaster;
00345
00346
00347 private:
00348
00349
00350 BluetoothDiscovery *iDiscovery;
00351
00352 RSocketServ iSocketServ;
00353
00354 TFixedArray<CConnector* ,KMaxConnectedDevices> iConnectedDevices;
00355
00356
00357 TDeviceDataList iDevDataList;
00358
00359 TInt iConnectedDeviceCount;
00360
00361 TTime iStartTime;
00362 TTime iEndTime;
00363 TBuf<KEighty> iResponse;
00364 TBuf<KTwenty> iMsgtext;
00365 TBuf8<KTwenty> iMsgtext8;
00366 };
00367
00368 #endif
00369
00370