Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OTGateway.h

Go to the documentation of this file.
00001 #ifndef OTGATEWAY_H
00002 #define OTGATEWAY_H
00003 
00004 #include <qobject.h>
00005 #include <qvector.h>
00006 #include <qmap.h>
00007 
00008 #include <OTDriverList.h>
00009 #include <OTInquiry.h>
00010 
00011 class QPixmap;
00012 
00013 namespace Opietooth2 {
00014 
00015 class OTDriverList;
00016 class OTDriver;
00017 class OTDevice;
00018 class OTPeer;
00019 class OTInquiry;
00020 class OTPANNetworkSetup;
00021 class OTLinkKey;
00022 
00023 typedef QVector<OTPeer> PeerVector;
00024 typedef QVector<OTPANNetworkSetup> PANNetworkSetupVector;
00025 typedef QArray<OTLinkKey> LinkKeyArray;
00026 
00027 class OTLinkKey {
00028 
00029 public :
00030 
00031     OTLinkKey( const OTDeviceAddress & F,
00032                const OTDeviceAddress & T ) {
00033       From = F;
00034       To = T;
00035     }
00036 
00037     const OTDeviceAddress & to()
00038       { return To; }
00039     const OTDeviceAddress & from()
00040       { return From; }
00041 
00042     OTDeviceAddress From;
00043     OTDeviceAddress To;
00044 };
00045 
00046 class OTPANNetworkSetup {
00047 
00048 public :
00049 
00050     OTPANNetworkSetup( const QString & Dev, const QString & CT ) {
00051       Device = Dev;
00052       ConnectedTo = CT;
00053     }
00054 
00055     QString Device;
00056     QString ConnectedTo;
00057 };
00058 
00059 
00060 class OTGateway : public QObject {
00061 
00062       Q_OBJECT
00063 
00064 public :
00065 
00066       // single instance
00067       static OTGateway * getOTGateway( void );
00068       static void releaseOTGateway( void );
00069       // convert device type as class to name for that class
00070       static const char * deviceTypeToName( int Cls );
00071 
00072       // open bluetooth system
00073       OTGateway( void );
00074       // close bluetooth system
00075       ~OTGateway( void );
00076 
00077       // get access to system device
00078       OTDevice * getOTDevice();
00079 
00080       // return true if this device needs enabling of bluetooth
00081       bool needsEnabling();
00082       // return true if system is running
00083       bool isEnabled();
00084       void setRefreshTimer( int MilleSecs );
00085       // return socket to HCI raw layer
00086       inline int getSocket()
00087         { return HciCtl; }
00088 
00089       OTDriverList & getDriverList()
00090         { return AllDrivers; }
00091       OTDriver * driver( int nr ) 
00092         { return AllDrivers.count() == 0 ? 0 : AllDrivers[nr]; }
00093       void updateDrivers();
00094 
00095       PANNetworkSetupVector getPANNetworkSetups();
00096 
00097       // scan neighbourhood using device
00098       void scanNeighbourhood( OTDriver * D = 0 );
00099       void stopScanOfNeighbourhood(void );
00100       void setScanWith( OTDriver * D = 0 ) 
00101         { ScanWith = (D) ? D : 
00102             (AllDrivers.count() ) ? AllDrivers[0] : 0; }
00103       OTDriver * scanWith( void )
00104         { return ScanWith; }
00105 
00106       // get list of all detected peers
00107       inline const PeerVector & peers( void )
00108         { return AllPeers; }
00109       // ping peer to see if it is up
00110       bool isPeerUp( const OTDeviceAddress & PAddr,
00111                      int timeoutInSec = 1,
00112                      int timeoutInUSec = 0,
00113                      int retry = 1 );
00114       OTPeer * findPeer( const OTDeviceAddress & Addr );
00115       void removePeer( OTPeer * P );
00116       void addPeer( OTPeer * P );
00117 
00118       OTDriver * findDriver( const OTDeviceAddress & Addr );
00119 
00120       inline const LinkKeyArray & getLinkKeys() const
00121         { return AllKeys; }
00122       bool removeLinkKey( unsigned int index );
00123 
00124       // return device number if we are connected over any device
00125       // to the channel
00126       // else returns -1
00127       int connectedToRFCommChannel( const OTDeviceAddress & Addr, int channel );
00128       int getFreeRFCommDevice( void );
00129       // return 0 if properly released
00130       int releaseRFCommDevice( int DevNr );
00131 
00132 public slots :
00133 
00134       // start bluetooth system
00135       void SLOT_SetEnabled( bool );
00136       void SLOT_Enable();
00137       void SLOT_Disable();
00138 
00139       // show error
00140       void SLOT_ShowError( const QString & );
00141 
00142       void SLOT_Enabled( int, bool );
00143       void SLOT_DriverDisappeared( OTDriver * );
00144       void SLOT_PeerDetected( OTPeer *, bool  );
00145       void SLOT_FinishedDetecting();
00146 
00147 signals :
00148 
00149       // any error
00150       void error( const QString & );
00151 
00152       // signal state of bluetooth driver
00153       void stateChange( OTDriver * D, bool State );
00154 
00155       // sent when list of drivers changees
00156       void driverListChanged();
00157 
00158       // sent when bluetooth on device is enabled
00159       void deviceEnabled( bool );
00160       
00161       // sent when a (new if bool = TRUE) peer is detected
00162       void detectedPeer( OTPeer *, bool );
00163 
00164       // end of detection process
00165       void finishedDetecting();
00166 
00167 protected :
00168 
00169       void connectNotify( const char * Signal );
00170       void disconnectNotify( const char * Signal );
00171 
00172       void timerEvent( QTimerEvent * );
00173 
00174 private :
00175 
00176       void loadActiveNetworkSetups( void );
00177       void loadKnownPeers( void );
00178       void saveKnownPeers( void );
00179       bool isConnectedTo( int devid,
00180                           const OTDeviceAddress & Address );
00181 
00182       void readLinkKeys();
00183 
00184       static OTGateway * SingleGateway;
00185       static int UseCount;
00186 
00187       OTDriver *      ScanWith;
00188       OTDriverList    AllDrivers;
00189       OTDevice *      TheOTDevice;
00190       int             HciCtl;
00191       int             ErrorConnectCount;
00192       int             RefreshTimer;
00193       OTInquiry *     Scanning;
00194       bool            AllPeersModified;
00195       PeerVector      AllPeers;
00196       LinkKeyArray    AllKeys;
00197 };
00198 }
00199 
00200 #endif

Generated on Sat Nov 5 16:17:55 2005 for OPIE by  doxygen 1.4.2