examples/ForumNokia/BluetoothPMPExample/inc/BluetoothPMPExampleEngine.h

00001 /*
00002  * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 #ifndef BLUETOOTHPMPEXAMPLEENGINE_H
00031 #define BLUETOOTHPMPEXAMPLEENGINE_H
00032 
00033 // INCLUDES
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 // maximum number of bluetooth device connections
00059 const TInt KMaxConnectedDevices=7;
00060 
00061 // length of label message buffer
00062 const TInt KMsgLength = 384;
00063 
00064 //avoiding magic numbers ;)
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 //the text displayed for devices with no name
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 // FORWARD DECLARATIONS
00108 class CBluetoothPMPExampleContainer;
00109 class CDeviceDiscoverer;
00110 class CServiceAdvertiser;
00111 class CServiceDiscoverer;
00112 class CListener;
00113 class CConnector;
00114 
00115 
00116 // CLASS DECLARATION
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& /* aAppUi */);
00138 
00143     static CBluetoothPMPExampleEngine* NewLC(
00144         CBluetoothPMPExampleAppUi& /* aAppUi */);
00145 
00151     ~CBluetoothPMPExampleEngine();
00152 
00153 public: // New functions
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     * From MDeviceDiscoObserver
00256     */
00257     void DeviceDiscovered(const TDeviceData &aDevice);
00258 
00265     void HandleServiceDiscoveryCompleteL();
00266 
00272     void ReportServiceDiscoveryErrorL(TInt aError);
00273 
00279     TBool HasConnections();
00280 
00281 /*
00282  * TurnBtOnL()
00283  * 
00284  * discussion
00285  * Uses the Notifier API to ask the user to turn on Bluetooth
00286  * if it's not on already.
00287  * HasConnection()
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: // in-class methods
00332 
00342     void ShowMessageL(const TDesC& /* aMsg */, TBool /* aDrawLine=EFalse */);
00343 
00344 
00345 private: // Basic two-phase EPOC constructors
00346 
00351     void ConstructL();
00352 
00358     CBluetoothPMPExampleEngine(CBluetoothPMPExampleAppUi& /* aAppUi */);
00359 
00360 
00361 public:     // data members
00362 
00363     // listener
00364     CListener* iListener;
00365     // device discoverer
00366     CDeviceDiscoverer* iDeviceDiscoverer;
00367     // service advertiser
00368     CServiceAdvertiser* iServiceAdvertiser;
00369     // service discoverer
00370     CServiceDiscoverer* iServiceDiscoverer;
00371     // true if the application is acting as a slave
00372     TBool iIsSlave;
00373     // true if the application is acting as a master
00374     TBool iIsMaster;
00375 
00376 private:    // data members
00377 
00378     // application UI object reference
00379     CBluetoothPMPExampleAppUi& iAppUi;
00380     // socket server
00381     RSocketServ iSocketServ;
00382     // array holding the connectors
00383     TFixedArray<CConnector* ,KMaxConnectedDevices> iConnectedDevices;
00384     
00385     // device data list reference
00386     TDeviceDataList iDevDataList;
00387     // number of slave connections master has
00388     TInt iConnectedDeviceCount;
00389     //for timing device disco:
00390     TTime iStartTime;
00391     TTime iEndTime;
00392     
00393     TBuf<KTwenty> iMsgtext;
00394     TBuf8<KTwenty> iMsgtext8;
00395 
00396 
00397 #ifdef ENABLE_LIAC
00398     //property for LimitedDiscoverableStatus
00399     RProperty   iProperty;
00400 
00401     //flag if LimitedDiscoverableStatus is enabled
00402     TBool iLIAC;
00403 #endif
00404 
00405 };
00406 
00407 #endif
00408 
00409 // End of File

Generated by  doxygen 1.6.2