examples/ForumNokia/BluetoothPMPExample/inc/BluetoothPMPExampleEngine.h

00001 /*
00002  * Copyright © 2009 Nokia Corporation.
00003  */
00004 
00005 #ifndef BLUETOOTHPMPEXAMPLEENGINE_H
00006 #define BLUETOOTHPMPEXAMPLEENGINE_H
00007 
00008 // INCLUDES
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 // maximum number of bluetooth device connections
00034 const TInt KMaxConnectedDevices=7;
00035 
00036 // length of label message buffer
00037 const TInt KMsgLength = 384;
00038 
00039 //avoiding magic numbers ;)
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 //the text displayed for devices with no name
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 // FORWARD DECLARATIONS
00083 class CBluetoothPMPExampleContainer;
00084 class CDeviceDiscoverer;
00085 class CServiceAdvertiser;
00086 class CServiceDiscoverer;
00087 class CListener;
00088 class CConnector;
00089 
00090 
00091 // CLASS DECLARATION
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& /* aAppUi */);
00113 
00118     static CBluetoothPMPExampleEngine* NewLC(
00119         CBluetoothPMPExampleAppUi& /* aAppUi */);
00120 
00126     ~CBluetoothPMPExampleEngine();
00127 
00128 public: // New functions
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     * From MDeviceDiscoObserver
00231     */
00232     void DeviceDiscovered(const TDeviceData &aDevice);
00233 
00240     void HandleServiceDiscoveryCompleteL();
00241 
00247     void ReportServiceDiscoveryErrorL(TInt aError);
00248 
00254     TBool HasConnections();
00255 
00256 /*
00257  * TurnBtOnL()
00258  * 
00259  * discussion
00260  * Uses the Notifier API to ask the user to turn on Bluetooth
00261  * if it's not on already.
00262  * HasConnection()
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: // in-class methods
00307 
00317     void ShowMessageL(const TDesC& /* aMsg */, TBool /* aDrawLine=EFalse */);
00318 
00319 
00320 private: // Basic two-phase EPOC constructors
00321 
00326     void ConstructL();
00327 
00333     CBluetoothPMPExampleEngine(CBluetoothPMPExampleAppUi& /* aAppUi */);
00334 
00335 
00336 public:     // data members
00337 
00338     // listener
00339     CListener* iListener;
00340     // device discoverer
00341     CDeviceDiscoverer* iDeviceDiscoverer;
00342     // service advertiser
00343     CServiceAdvertiser* iServiceAdvertiser;
00344     // service discoverer
00345     CServiceDiscoverer* iServiceDiscoverer;
00346     // true if the application is acting as a slave
00347     TBool iIsSlave;
00348     // true if the application is acting as a master
00349     TBool iIsMaster;
00350 
00351 private:    // data members
00352 
00353     // application UI object reference
00354     CBluetoothPMPExampleAppUi& iAppUi;
00355     // socket server
00356     RSocketServ iSocketServ;
00357     // array holding the connectors
00358     TFixedArray<CConnector* ,KMaxConnectedDevices> iConnectedDevices;
00359     
00360     // device data list reference
00361     TDeviceDataList iDevDataList;
00362     // number of slave connections master has
00363     TInt iConnectedDeviceCount;
00364     //for timing device disco:
00365     TTime iStartTime;
00366     TTime iEndTime;
00367     
00368     TBuf<KTwenty> iMsgtext;
00369     TBuf8<KTwenty> iMsgtext8;
00370 
00371 
00372 #ifdef ENABLE_LIAC
00373     //property for LimitedDiscoverableStatus
00374     RProperty   iProperty;
00375 
00376     //flag if LimitedDiscoverableStatus is enabled
00377     TBool iLIAC;
00378 #endif
00379 
00380 };
00381 
00382 #endif
00383 
00384 // End of File

Generated by  doxygen 1.6.2