00001
00002
00003
00004
00005 #ifndef BLUETOOTHPMPEXAMPLEENGINE_H
00006 #define BLUETOOTHPMPEXAMPLEENGINE_H
00007
00008
00009 #include <e32base.h>
00010 #include <aknviewappui.h>
00011
00012 #include <coecntrl.h>
00013 #include <es_sock.h>
00014 #include <btdevice.h>
00015 #include <bt_sock.h>
00016 #include <btsdp.h>
00017 #include <btmanclient.h>
00018
00019 #ifdef ENABLE_LIAC
00020 #include <e32property.h>
00021 #endif
00022
00023 #include "BluetoothPMPExample.hrh"
00024 #include "BluetoothPMPExampleRTEContainer.h"
00025 #include "BluetoothPMPExampleAppUi.h"
00026
00027 #include "Common.h"
00028 #include "DeviceDiscoverer.h"
00029 #include "ServiceDiscoverer.h"
00030 #include "Listener.h"
00031 #include "Connector.h"
00032
00033
00034 const TInt KMaxConnectedDevices=7;
00035
00036
00037 const TInt KMsgLength = 384;
00038
00039
00040 const TInt KThirty = 30;
00041 const TInt KTwenty = 20;
00042 const TInt KEighty = 80;
00043 const TInt KTwelve = 12;
00044 const TInt KForty = 40;
00045
00046
00047 _LIT(KDeviceWithNoName,"*Jane Doe*");
00048 _LIT(KNoServiceFound,"No services found!\n");
00049 _LIT(KNewLine,"\n");
00050 _LIT(KServiceFound,"Found service on:\n");
00051 _LIT(KNoDevFound,"\nNo devices found!");
00052 _LIT(KDevices," devices.");
00053 _LIT(KFoundTxt,"Found ");
00054 _LIT(KSecTxt," s.");
00055 _LIT(KTimeTxt,"time ");
00056 _LIT(KFormatStr,"< %S: %S\n");
00057 _LIT(KDisconMsg,"Disconnected!\nSlave stopped.\n");
00058 _LIT(KDeviceDisconMsg,"%S disconnected!\n");
00059 _LIT(KConnMsg,"Connected!\n");
00060 _LIT(KFormatStr1,"< %S\n");
00061 _LIT(KFormatStr2,"> %S: %S\n");
00062 _LIT(KFormatStr3,"> %S\n");
00063 _LIT(KMessage,"message");
00064 _LIT(KNoConns,"No connections!");
00065 _LIT(KConnDevicesTxt,"Connected devices:\n");
00066 _LIT(KConnectingTxt, "Connecting...\n");
00067 _LIT(KDisconnDevicesTxt, "Devices disconnected\n");
00068 _LIT(KSlaveInitCompTxt,"\nSlave init complete!\nWaiting for connection.");
00069 _LIT(KListeningTxt,"\nListening channel %d");
00070 _LIT(KSlaveInitTxt,"Slave init..");
00071 _LIT(KDiscServicesTxt,"Discovering services,\nplease wait...\n");
00072 _LIT(KDiscDevicesTxt,"Discovering devices,\nplease wait...\n");
00073
00074 _LIT(KServiceDiscoveryError, "Serv disco error:");
00075 _LIT(KTurningOn, "Turning bt on");
00076
00077 _LIT(KLIACError, "There was an erron on setting LIAC status: %d" );
00078 _LIT(KLIACOn, "LIAC has been enabled" );
00079 _LIT(KLIACOff, "LIAC has been disabled" );
00080
00081
00082
00083 class CBluetoothPMPExampleContainer;
00084 class CDeviceDiscoverer;
00085 class CServiceAdvertiser;
00086 class CServiceDiscoverer;
00087 class CListener;
00088 class CConnector;
00089
00090
00091
00092
00097 class CBluetoothPMPExampleEngine : public CBase,
00098 public MListenerObserver,
00099 public MConnectorObserver,
00100 public MDeviceDiscoObserver,
00101 public MServiceDiscoObserver
00102 {
00103 public:
00104
00111 static CBluetoothPMPExampleEngine* NewL(
00112 CBluetoothPMPExampleAppUi& );
00113
00118 static CBluetoothPMPExampleEngine* NewLC(
00119 CBluetoothPMPExampleAppUi& );
00120
00126 ~CBluetoothPMPExampleEngine();
00127
00128 public:
00129
00136 void DiscoverDevicesL();
00137
00143 void DiscoverServicesL();
00144
00152 void StartSlaveL();
00153
00154 void StopSlaveL();
00155
00162 void SendMessageL();
00163
00170 void ConnectDevicesL();
00171
00177 void DisconnectDevices();
00178
00184 void ShowConnectedDevicesL();
00185
00193 void HandleListenerDataReceivedL(const TDesC& aData);
00194
00203 void HandleConnectorDataReceivedL(THostName aName, const TDesC& aData);
00204 void HandleConnectorErrorL(THostName aName, TInt aError);
00211 void HandleListenerConnectedL();
00212
00219 void HandleListenerDisconnectedL();
00220
00227 void HandleDeviceDiscoveryComplete(TInt aError);
00228
00229
00230
00231
00232 void DeviceDiscovered(const TDeviceData &aDevice);
00233
00240 void HandleServiceDiscoveryCompleteL();
00241
00247 void ReportServiceDiscoveryErrorL(TInt aError);
00248
00254 TBool HasConnections();
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 void TurnBtOnL();
00267
00268 #ifdef ENABLE_LIAC
00269
00276 void SetLIAC( TBool aState );
00277
00285 TBool LIAC();
00286 #endif
00287
00295 TBool IsDiscoveryActive();
00296
00304 void StopDiscovery();
00305
00306 private:
00307
00317 void ShowMessageL(const TDesC& , TBool );
00318
00319
00320 private:
00321
00326 void ConstructL();
00327
00333 CBluetoothPMPExampleEngine(CBluetoothPMPExampleAppUi& );
00334
00335
00336 public:
00337
00338
00339 CListener* iListener;
00340
00341 CDeviceDiscoverer* iDeviceDiscoverer;
00342
00343 CServiceAdvertiser* iServiceAdvertiser;
00344
00345 CServiceDiscoverer* iServiceDiscoverer;
00346
00347 TBool iIsSlave;
00348
00349 TBool iIsMaster;
00350
00351 private:
00352
00353
00354 CBluetoothPMPExampleAppUi& iAppUi;
00355
00356 RSocketServ iSocketServ;
00357
00358 TFixedArray<CConnector* ,KMaxConnectedDevices> iConnectedDevices;
00359
00360
00361 TDeviceDataList iDevDataList;
00362
00363 TInt iConnectedDeviceCount;
00364
00365 TTime iStartTime;
00366 TTime iEndTime;
00367
00368 TBuf<KTwenty> iMsgtext;
00369 TBuf8<KTwenty> iMsgtext8;
00370
00371
00372 #ifdef ENABLE_LIAC
00373
00374 RProperty iProperty;
00375
00376
00377 TBool iLIAC;
00378 #endif
00379
00380 };
00381
00382 #endif
00383
00384