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 BLUETOOTHPMPEXAMPLEENGINE_H
00031 #define BLUETOOTHPMPEXAMPLEENGINE_H
00032
00033
00034 #include <e32base.h>
00035 #include <aknviewappui.h>
00036
00037 #include <coecntrl.h>
00038 #include <es_sock.h>
00039 #include <btdevice.h>
00040 #include <bt_sock.h>
00041 #include <btsdp.h>
00042 #include <btmanclient.h>
00043
00044 #ifdef ENABLE_LIAC
00045 #include <e32property.h>
00046 #endif
00047
00048 #include "BluetoothPMPExample.hrh"
00049 #include "BluetoothPMPExampleRTEContainer.h"
00050 #include "BluetoothPMPExampleAppUi.h"
00051
00052 #include "Common.h"
00053 #include "DeviceDiscoverer.h"
00054 #include "ServiceDiscoverer.h"
00055 #include "Listener.h"
00056 #include "Connector.h"
00057
00058
00059 const TInt KMaxConnectedDevices=7;
00060
00061
00062 const TInt KMsgLength = 384;
00063
00064
00065 const TInt KThirty = 30;
00066 const TInt KTwenty = 20;
00067 const TInt KEighty = 80;
00068 const TInt KTwelve = 12;
00069 const TInt KForty = 40;
00070
00071
00072 _LIT(KDeviceWithNoName,"*Jane Doe*");
00073 _LIT(KNoServiceFound,"No services found!\n");
00074 _LIT(KNewLine,"\n");
00075 _LIT(KServiceFound,"Found service on:\n");
00076 _LIT(KNoDevFound,"\nNo devices found!");
00077 _LIT(KDevices," devices.");
00078 _LIT(KFoundTxt,"Found ");
00079 _LIT(KSecTxt," s.");
00080 _LIT(KTimeTxt,"time ");
00081 _LIT(KFormatStr,"< %S: %S\n");
00082 _LIT(KDisconMsg,"Disconnected!\nSlave stopped.\n");
00083 _LIT(KDeviceDisconMsg,"%S disconnected!\n");
00084 _LIT(KConnMsg,"Connected!\n");
00085 _LIT(KFormatStr1,"< %S\n");
00086 _LIT(KFormatStr2,"> %S: %S\n");
00087 _LIT(KFormatStr3,"> %S\n");
00088 _LIT(KMessage,"message");
00089 _LIT(KNoConns,"No connections!");
00090 _LIT(KConnDevicesTxt,"Connected devices:\n");
00091 _LIT(KConnectingTxt, "Connecting...\n");
00092 _LIT(KDisconnDevicesTxt, "Devices disconnected\n");
00093 _LIT(KSlaveInitCompTxt,"\nSlave init complete!\nWaiting for connection.");
00094 _LIT(KListeningTxt,"\nListening channel %d");
00095 _LIT(KSlaveInitTxt,"Slave init..");
00096 _LIT(KDiscServicesTxt,"Discovering services,\nplease wait...\n");
00097 _LIT(KDiscDevicesTxt,"Discovering devices,\nplease wait...\n");
00098
00099 _LIT(KServiceDiscoveryError, "Serv disco error:");
00100 _LIT(KTurningOn, "Turning bt on");
00101
00102 _LIT(KLIACError, "There was an erron on setting LIAC status: %d" );
00103 _LIT(KLIACOn, "LIAC has been enabled" );
00104 _LIT(KLIACOff, "LIAC has been disabled" );
00105
00106
00107
00108 class CBluetoothPMPExampleContainer;
00109 class CDeviceDiscoverer;
00110 class CServiceAdvertiser;
00111 class CServiceDiscoverer;
00112 class CListener;
00113 class CConnector;
00114
00115
00116
00117
00122 class CBluetoothPMPExampleEngine : public CBase,
00123 public MListenerObserver,
00124 public MConnectorObserver,
00125 public MDeviceDiscoObserver,
00126 public MServiceDiscoObserver
00127 {
00128 public:
00129
00136 static CBluetoothPMPExampleEngine* NewL(
00137 CBluetoothPMPExampleAppUi& );
00138
00143 static CBluetoothPMPExampleEngine* NewLC(
00144 CBluetoothPMPExampleAppUi& );
00145
00151 ~CBluetoothPMPExampleEngine();
00152
00153 public:
00154
00161 void DiscoverDevicesL();
00162
00168 void DiscoverServicesL();
00169
00177 void StartSlaveL();
00178
00179 void StopSlaveL();
00180
00187 void SendMessageL();
00188
00195 void ConnectDevicesL();
00196
00202 void DisconnectDevices();
00203
00209 void ShowConnectedDevicesL();
00210
00218 void HandleListenerDataReceivedL(const TDesC& aData);
00219
00228 void HandleConnectorDataReceivedL(THostName aName, const TDesC& aData);
00229 void HandleConnectorErrorL(THostName aName, TInt aError);
00236 void HandleListenerConnectedL();
00237
00244 void HandleListenerDisconnectedL();
00245
00252 void HandleDeviceDiscoveryComplete(TInt aError);
00253
00254
00255
00256
00257 void DeviceDiscovered(const TDeviceData &aDevice);
00258
00265 void HandleServiceDiscoveryCompleteL();
00266
00272 void ReportServiceDiscoveryErrorL(TInt aError);
00273
00279 TBool HasConnections();
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 void TurnBtOnL();
00292
00293 #ifdef ENABLE_LIAC
00294
00301 void SetLIAC( TBool aState );
00302
00310 TBool LIAC();
00311 #endif
00312
00320 TBool IsDiscoveryActive();
00321
00329 void StopDiscovery();
00330
00331 private:
00332
00342 void ShowMessageL(const TDesC& , TBool );
00343
00344
00345 private:
00346
00351 void ConstructL();
00352
00358 CBluetoothPMPExampleEngine(CBluetoothPMPExampleAppUi& );
00359
00360
00361 public:
00362
00363
00364 CListener* iListener;
00365
00366 CDeviceDiscoverer* iDeviceDiscoverer;
00367
00368 CServiceAdvertiser* iServiceAdvertiser;
00369
00370 CServiceDiscoverer* iServiceDiscoverer;
00371
00372 TBool iIsSlave;
00373
00374 TBool iIsMaster;
00375
00376 private:
00377
00378
00379 CBluetoothPMPExampleAppUi& iAppUi;
00380
00381 RSocketServ iSocketServ;
00382
00383 TFixedArray<CConnector* ,KMaxConnectedDevices> iConnectedDevices;
00384
00385
00386 TDeviceDataList iDevDataList;
00387
00388 TInt iConnectedDeviceCount;
00389
00390 TTime iStartTime;
00391 TTime iEndTime;
00392
00393 TBuf<KTwenty> iMsgtext;
00394 TBuf8<KTwenty> iMsgtext8;
00395
00396
00397 #ifdef ENABLE_LIAC
00398
00399 RProperty iProperty;
00400
00401
00402 TBool iLIAC;
00403 #endif
00404
00405 };
00406
00407 #endif
00408
00409