examples/QtQuick/bluetoothex/bluetoothex_symbian.h

00001 /*
00002  * Copyright (c) 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 BLUETOOTHDISCOVERY_SYMBIAN_H
00031 #define BLUETOOTHDISCOVERY_SYMBIAN_H
00032 
00033 // INCLUDES
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 "bluetoothex.h"
00048 
00049 // maximum number of bluetooth device connections
00050 const TInt KMaxConnectedDevices=7;
00051 
00052 // length of label message buffer
00053 const TInt KMsgLength = 384;
00054 
00055 //avoiding magic numbers ;)
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 //the text displayed for devices with no name
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 // FORWARD DECLARATIONS
00095 class CDeviceDiscoverer;
00096 class CServiceAdvertiser;
00097 class CServiceDiscoverer;
00098 class CListener;
00099 class CConnector;
00100 
00101 
00102 // CLASS DECLARATION
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     EStartSlave,
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: // New functions
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     * From MDeviceDiscoObserver
00249     */
00250     void DeviceDiscovered(const TDeviceData &aDevice);
00251 
00258     void HandleServiceDiscoveryCompleteL();
00259 
00265     void ReportServiceDiscoveryErrorL(TInt aError);
00266 
00272     TBool HasConnections();
00273 
00274 /*
00275  * TurnBtOnL()
00276  * 
00277  * Uses the Notifier API to ask the user to turn on Bluetooth
00278  * if it's not on already.
00279  * HasConnection()
00280  *
00281  * 
00282  */
00283     void TurnBtOnL();
00284   
00291     TBool IsDiscoveryActive();
00292 
00299     void StopDiscovery();
00300 
00301 private: // in-class methods
00302 
00312     void ChangeMenuOptions();
00313 
00314 
00315 private: // Basic two-phase EPOC constructors
00316 
00321     void ConstructL();
00322 
00328     BluetoothDiscoveryPrivate(BluetoothDiscovery* /* aWrapper */);
00329 
00330 
00331 public:     // data members
00332 
00333     // Listener
00334     CListener* iListener;
00335     // Device discoverer
00336     CDeviceDiscoverer* iDeviceDiscoverer;
00337     // Service advertiser
00338     CServiceAdvertiser* iServiceAdvertiser;
00339     // Service discoverer
00340     CServiceDiscoverer* iServiceDiscoverer;
00341     // True if the application is acting as a master
00342     TBool iIsMaster;
00343     // True if the application is acting as a slave
00344     TBool iIsSlave;
00345 
00346 
00347 private:    // data members
00348 
00349     // Wrapper class
00350     BluetoothDiscovery *iDiscovery;
00351     // Socket server
00352     RSocketServ iSocketServ;
00353     // Array holding the connectors
00354     TFixedArray<CConnector* ,KMaxConnectedDevices> iConnectedDevices;
00355     
00356     // Device data list reference
00357     TDeviceDataList iDevDataList;
00358     // Number of slave connections master has
00359     TInt iConnectedDeviceCount;
00360     // For timing device disco:
00361     TTime iStartTime;
00362     TTime iEndTime;
00363     TBuf<KEighty> iResponse;
00364     TBuf<KTwenty> iMsgtext;
00365     TBuf8<KTwenty> iMsgtext8;    
00366 };
00367 
00368 #endif
00369 
00370 // End of File

Generated by  doxygen 1.6.2