summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/opietooth2/OTPeer.h
blob: c09af155b226d453f839977f20729d645dcdf1ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//-*-c++-*-
/***************************************************************************
 *   Copyright (C) 2003 by Fred Schaettgen                                 *
 *   kdebluetooth@0xF.de                                                   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#ifndef OTPEER_H
#define OTPEER_H

#include <qstring.h>
#include <qobject.h>
#include <qvector.h>
#include <bluezlib.h>
#include <OTDeviceAddress.h>

class QTextStream;
class QTimerEvent;

namespace Opietooth2 {

class OTGateway;

class OTDriver;
class OTSDPService;
class OTSDPAttribute;
class OTUUID;
typedef QVector<OTSDPService> ServiceVector;

class OTPeer : public QObject {

      Q_OBJECT;

public :

      typedef enum PeerState_E {
        Peer_Unknown = -1,
        Peer_Down = 0,
        Peer_Up = 1
      } PeerState_t;

      OTPeer( OTGateway * _OT );
      OTPeer( QTextStream & TS, OTGateway * _TS );
      ~OTPeer();

      inline OTGateway * gateway() const
        { return OT; }

      inline int deviceClass( void ) const 
        { return Class; }
      inline void setDeviceClass( int cls )
        { Class = cls; }

      void setAddress( const OTDeviceAddress & A ) 
        { Addr = A; }

      const OTDeviceAddress & address( void )
        { return Addr; }

      inline QString name( void ) const 
        { return Name; }
      inline void setName( const QString & n )
        { Name = n; }

      ServiceVector & services( bool Force = 0 )
        { if( Force || serviceList.count() == 0 ) {
            updateServices();
          }
          return serviceList;
        }

      /* Returns TRUE if the device has at least a service 
         with inside the required class Id.*/
      bool hasServiceClassID( const OTUUID & uuid);

      /* Get a vector of Rfcomm channels of the services 
         having "uuid" in the class ID List */
      QArray<int> rfcommList( const OTUUID & uuid );

      inline void setState( PeerState_t S) 
        { State = S; }
      inline PeerState_t state( void )
        { return State; }

      // go and find out state
      // will report back with signal
      void findOutState( int timeoutInSec = 1, bool Force = 0 );
      void stopFindingOutState( void );

      // return driver to which this peer is connected to
      // if it is connected
      inline OTDriver * connectedTo( void ) const
        { return ConnectedTo; }
      inline void setConnectedTo( OTDriver * D ) 
        { ConnectedTo = D; }

      void save( QTextStream& TS ); 
      void load( QTextStream& TS ); 

signals :

      // report back state
      void peerStateReport( OTPeer *);
      void error( const QString & );

protected :

      // while polling for result of ping
      void timerEvent( QTimerEvent * ev );

private:

      void updateServices();

      OTGateway * OT;
      OTDeviceAddress Addr;
      QString Name;
      int Class;
      ServiceVector serviceList;
      // -1 : don't know, 0 no, 1 yes
      PeerState_t State;
      OTDriver * ConnectedTo;

      int ProbeFD;
      int ProbePhase; // see OTDriver
      long ProbeTimeout;
};

}

#endif