summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/lib/connection.h
blob: a0c50f2461357f6c942ff698b5bbed49b242de96 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

#ifndef OpieTooth_Connection_H
#define OpieTooth_Connection_H

#include <qstring.h>
#include <qvaluelist.h>
#include <qobject.h>

namespace OpieTooth {

	


    /**
     * Parent class for all kinds of starting connection 
     * subclasses
     *
     */
    class StartConnection : public QObject {

    protected:

	enum ConnectionType{
	    Pan = 0,
	    Rfcomm,
	    Obex,
	    Hci
	};

	virtual ~StartConnection() {};

	virtual QString name() = 0;
	virtual void setName( QString name ) = 0;
	virtual ConnectionType type() = 0;
	virtual void setConnectionType() = 0;
        virtual void start() = 0;
	virtual void stop() = 0;

    };

    enum LinkDirection { Incoming= true, Outgoing = false };
    enum LinkMode { Master =0, Client };


    /**
     * The Connection class stores
     * the output of hcitool con
     * in a OO way
     */

    class ConnectionState {
    public:
        /**
         * typedef for a list of
         * Connections
         */
        typedef QValueList<ConnectionState> ValueList;

        /**
         * Copy c'tor.
         */
        ConnectionState( const ConnectionState& );

        /**
         * Main c'tor
         * Basicly it holds all values
         * a blueZ connections can have
         * @param in If the connection is either incoming or outgoing
         * @param conType Either ACL or SCO for connection type
         * @param mac The BD Address( mac ) of the peer
         * @param handle the blueZ handle
         * @param state the State of the connection
         * @param linkMode the linkmode of the connection MASTER or not
         *
         * < ACL 00:02:C7:09:2B:53 handle 1 state 1 lm MASTER
         *
         */
        ConnectionState( bool in,
                    const QString& conType,
                    const QString& mac,
                    int handle,
                    int state,
                    int linkMode );

        /**
         * C'tor for compability with QValueList
         * QValueList needs this c'tor.
         */
        ConnectionState();

        /**
         * Set if the connection is incoming or
         * outgoing
         * @param in Whether or not the connection is ingoing or not.
         * for param use either Incoming or Outgoing
         *
         */
        void setDirection( bool incoming = Incoming );

        /**
         * direction() will return Incoming( true )
         * if the direction is incomoning or Outgoing( false)
         * if outgoing
         */
        bool direction() const;

        /**
         * sets the ConnectionMode
         * @param comMode I know that SCO and ACL exists so far
         */
        void setConnectionMode( const QString& comMode );

        /**
         * linkMode returns the linkMode
         * MASTER for example
         */
        QString connectionMode() const;

        /**
         * The Bluetooth Address or mac
         * is set by this function
         * @param mac the BluetoothAddress( mac)
         */
        void setMac( const QString& mac);

        /**
         * returns the mac
         */
        QString mac() const;


        /**
         * Set the handle of the bt connection
         */
        void setHandle(int handle );

        /**
         * @return the handle of the connection
         */
        int handle() const;

        /**
         * sets the state
         */
        void setState( int state );

        /**
         * return the state
         */
        int state() const;

        /**
         * Sets the link mode of the Connection
         */
        void setLinkMode( int linkMode = Master );

        /**
         * returns the linkMode
         */
        int linkMode()const;

        /**
         * copy c'tor
         */
        ConnectionState &operator=( const ConnectionState& );

    private:
        class ConnectionStatePrivate;
        ConnectionStatePrivate *d;
        bool m_direction : 1;
        QString m_contype;
        QString m_mac;
        int m_handle;
        int m_state;
        int m_linkMode;

    };
};


#endif