author | zecke <zecke> | 2002-06-28 20:41:55 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-06-28 20:41:55 (UTC) |
commit | 545d7b51d67e4c1fa6be40436103b0a6b237a3a7 (patch) (unidiff) | |
tree | 7a40a66ef8798e51a23ac362254788609f818f17 | |
parent | 8a34a47d873d8d767d0a84a828e6724b73295b8d (diff) | |
download | opie-545d7b51d67e4c1fa6be40436103b0a6b237a3a7.zip opie-545d7b51d67e4c1fa6be40436103b0a6b237a3a7.tar.gz opie-545d7b51d67e4c1fa6be40436103b0a6b237a3a7.tar.bz2 |
hcitool con additions ( not done yet )
-rw-r--r-- | noncore/net/opietooth/lib/connection.cpp | 90 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/connection.h | 150 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/lib.pro | 4 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/manager.h | 231 |
4 files changed, 366 insertions, 109 deletions
diff --git a/noncore/net/opietooth/lib/connection.cpp b/noncore/net/opietooth/lib/connection.cpp new file mode 100644 index 0000000..1f9baaf --- a/dev/null +++ b/noncore/net/opietooth/lib/connection.cpp | |||
@@ -0,0 +1,90 @@ | |||
1 | |||
2 | #include "connection.h" | ||
3 | |||
4 | using namespace OpieTooth; | ||
5 | |||
6 | Connection::Connection() { | ||
7 | m_direction = Incoming; | ||
8 | m_handle = -1; | ||
9 | m_state = -1; | ||
10 | m_linkMode = -1; | ||
11 | }; | ||
12 | |||
13 | Connection::Connection( const Connection& con1 ) { | ||
14 | (*this) = con1; | ||
15 | } | ||
16 | |||
17 | |||
18 | Connection::Connection( bool in, | ||
19 | const QString& conType, | ||
20 | const QString& mac, | ||
21 | int handle, | ||
22 | int state, | ||
23 | int linkMode ) { | ||
24 | m_direction = in; | ||
25 | m_contype = conType; | ||
26 | m_mac = mac; | ||
27 | m_handle = handle; | ||
28 | m_state = state; | ||
29 | m_linkMode = linkMode; | ||
30 | |||
31 | } | ||
32 | |||
33 | void Connection::setDirection( bool incoming ) { | ||
34 | m_direction = incoming; | ||
35 | } | ||
36 | |||
37 | bool Connection::direction() const { | ||
38 | return m_direction; | ||
39 | } | ||
40 | |||
41 | void Connection::setConnectionMode( const QString& conType ) { | ||
42 | m_contype = conType; | ||
43 | } | ||
44 | |||
45 | QString Connection::connectionMode() const { | ||
46 | return m_contype; | ||
47 | } | ||
48 | |||
49 | void Connection::setMac( const QString& mac ) { | ||
50 | m_mac = mac; | ||
51 | } | ||
52 | |||
53 | QString Connection::mac() const{ | ||
54 | return m_mac; | ||
55 | } | ||
56 | |||
57 | void Connection::setHandle( int handle ) { | ||
58 | m_handle = handle; | ||
59 | } | ||
60 | |||
61 | int Connection::handle() const{ | ||
62 | return m_handle; | ||
63 | } | ||
64 | |||
65 | void Connection::setState( int state ) { | ||
66 | m_state = state; | ||
67 | } | ||
68 | |||
69 | int Connection::state()const { | ||
70 | return m_state; | ||
71 | } | ||
72 | |||
73 | void Connection::setLinkMode( int linkMode ) { | ||
74 | m_linkMode = linkMode; | ||
75 | } | ||
76 | |||
77 | int Connection::linkMode()const{ | ||
78 | return m_linkMode; | ||
79 | } | ||
80 | |||
81 | Connection &Connection::operator=( const Connection& con1 ) { | ||
82 | m_direction = con1.m_direction; | ||
83 | m_contype = con1.m_contype; | ||
84 | m_mac = con1.m_mac; | ||
85 | m_handle = con1.m_handle; | ||
86 | m_state = con1.m_state; | ||
87 | m_linkMode = con1.m_linkMode; | ||
88 | |||
89 | return (*this); | ||
90 | } | ||
diff --git a/noncore/net/opietooth/lib/connection.h b/noncore/net/opietooth/lib/connection.h new file mode 100644 index 0000000..37090ce --- a/dev/null +++ b/noncore/net/opietooth/lib/connection.h | |||
@@ -0,0 +1,150 @@ | |||
1 | |||
2 | #ifndef OpieTooth_Connection_H | ||
3 | #define OpieTooth_Connection_H | ||
4 | |||
5 | #include <qstring.h> | ||
6 | #include <qvaluelist.h> | ||
7 | |||
8 | namespace OpieTooth { | ||
9 | |||
10 | enum LinkDirection { Incoming= true, Outgoing = false }; | ||
11 | enum LinkMode { Master =0, Client }; | ||
12 | |||
13 | |||
14 | /** | ||
15 | * The Connection class stores | ||
16 | * the output of hcitool con | ||
17 | * in a OO way | ||
18 | */ | ||
19 | |||
20 | class Connection { | ||
21 | public: | ||
22 | /** | ||
23 | * typedef for a list of | ||
24 | * Connections | ||
25 | */ | ||
26 | typedef QValueList<Connection> ValueList; | ||
27 | |||
28 | /** | ||
29 | * Copy c'tor. | ||
30 | */ | ||
31 | Connection( const Connection& ); | ||
32 | |||
33 | /** | ||
34 | * Main c'tor | ||
35 | * Basicly it holds all values | ||
36 | * a blueZ connections can have | ||
37 | * @param in If the connection is either incoming or outgoing | ||
38 | * @param conType Either ACL or SCO for connection type | ||
39 | * @param mac The BD Address( mac ) of the peer | ||
40 | * @param handle the blueZ handle | ||
41 | * @param state the State of the connection | ||
42 | * @param linkMode the linkmode of the connection MASTER or not | ||
43 | * | ||
44 | * < ACL 00:02:C7:09:2B:53 handle 1 state 1 lm MASTER | ||
45 | * | ||
46 | */ | ||
47 | Connection( bool in, | ||
48 | const QString& conType, | ||
49 | const QString& mac, | ||
50 | int handle, | ||
51 | int state, | ||
52 | int linkMode ); | ||
53 | |||
54 | /** | ||
55 | * C'tor for compability with QValueList | ||
56 | * QValueList needs this c'tor. | ||
57 | */ | ||
58 | Connection(); | ||
59 | |||
60 | /** | ||
61 | * Set if the connection is incoming or | ||
62 | * outgoing | ||
63 | * @param in Whether or not the connection is ingoing or not. | ||
64 | * for param use either Incoming or Outgoing | ||
65 | * | ||
66 | */ | ||
67 | void setDirection( bool incoming = Incoming ); | ||
68 | |||
69 | /** | ||
70 | * direction() will return Incoming( true ) | ||
71 | * if the direction is incomoning or Outgoing( false) | ||
72 | * if outgoing | ||
73 | */ | ||
74 | bool direction() const; | ||
75 | |||
76 | /** | ||
77 | * sets the ConnectionMode | ||
78 | * @param comMode I know that SCO and ACL exists so far | ||
79 | */ | ||
80 | void setConnectionMode( const QString& comMode ); | ||
81 | |||
82 | /** | ||
83 | * linkMode returns the linkMode | ||
84 | * MASTER for example | ||
85 | */ | ||
86 | QString connectionMode() const; | ||
87 | |||
88 | /** | ||
89 | * The Bluetooth Address or mac | ||
90 | * is set by this function | ||
91 | * @param mac the BluetoothAddress( mac) | ||
92 | */ | ||
93 | void setMac( const QString& mac); | ||
94 | |||
95 | /** | ||
96 | * returns the mac | ||
97 | */ | ||
98 | QString mac() const; | ||
99 | |||
100 | |||
101 | /** | ||
102 | * Set the handle of the bt connection | ||
103 | */ | ||
104 | void setHandle(int handle ); | ||
105 | |||
106 | /** | ||
107 | * @return the handle of the connection | ||
108 | */ | ||
109 | int handle() const; | ||
110 | |||
111 | /** | ||
112 | * sets the state | ||
113 | */ | ||
114 | void setState( int state ); | ||
115 | |||
116 | /** | ||
117 | * return the state | ||
118 | */ | ||
119 | int state() const; | ||
120 | |||
121 | /** | ||
122 | * Sets the link mode of the Connection | ||
123 | */ | ||
124 | void setLinkMode( int linkMode = Master ); | ||
125 | |||
126 | /** | ||
127 | * returns the linkMode | ||
128 | */ | ||
129 | int linkMode()const; | ||
130 | |||
131 | /** | ||
132 | * copy c'tor | ||
133 | */ | ||
134 | Connection &operator=( const Connection& ); | ||
135 | |||
136 | private: | ||
137 | class ConnectionPrivate; | ||
138 | ConnectionPrivate *d; | ||
139 | bool m_direction : 1; | ||
140 | QString m_contype; | ||
141 | QString m_mac; | ||
142 | int m_handle; | ||
143 | int m_state; | ||
144 | int m_linkMode; | ||
145 | |||
146 | }; | ||
147 | }; | ||
148 | |||
149 | |||
150 | #endif | ||
diff --git a/noncore/net/opietooth/lib/lib.pro b/noncore/net/opietooth/lib/lib.pro index ecf2e6c..dde6c2a 100644 --- a/noncore/net/opietooth/lib/lib.pro +++ b/noncore/net/opietooth/lib/lib.pro | |||
@@ -1,7 +1,7 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qte warn_on release | 2 | CONFIG += qte warn_on release |
3 | HEADERS = parser.h device.h manager.h remotedevice.h services.h | 3 | HEADERS = connection.h parser.h device.h manager.h remotedevice.h services.h |
4 | SOURCES = parser.cc device.cc manager.cc remotedevice.cc services.cc | 4 | SOURCES = connection.cpp parser.cc device.cc manager.cc remotedevice.cc services.cc |
5 | TARGET = opietooth | 5 | TARGET = opietooth |
6 | INCLUDEPATH += $(OPIEDIR)/include . | 6 | INCLUDEPATH += $(OPIEDIR)/include . |
7 | DESTDIR = $(QTDIR)/lib$(PROJMAK) | 7 | DESTDIR = $(QTDIR)/lib$(PROJMAK) |
diff --git a/noncore/net/opietooth/lib/manager.h b/noncore/net/opietooth/lib/manager.h index 415ec72..2589e9b 100644 --- a/noncore/net/opietooth/lib/manager.h +++ b/noncore/net/opietooth/lib/manager.h | |||
@@ -12,120 +12,137 @@ | |||
12 | 12 | ||
13 | class OProcess; | 13 | class OProcess; |
14 | namespace OpieTooth { | 14 | namespace OpieTooth { |
15 | class Device; | 15 | class Device; |
16 | /** Manager manages a blueZ device (hci0 for example) | 16 | /** Manager manages a blueZ device (hci0 for example) |
17 | * with Manager you can control the things you | 17 | * without Manager you can control the things you |
18 | * could do from command line in a OO and asynchronus | 18 | * could do from command line in a OO and asynchronus |
19 | * way. | 19 | * way. |
20 | */ | ||
21 | class Manager : public QObject { | ||
22 | Q_OBJECT | ||
23 | public: | ||
24 | /** c'tor whichs create a new Manager | ||
25 | * @param device is the device to use. Either a mac or blueZ device name | ||
26 | * | ||
27 | */ | 20 | */ |
28 | Manager( const QString &device ); | 21 | class Manager : public QObject { |
29 | /** c'tor | 22 | Q_OBJECT |
30 | * @param dev The Device to be managed | 23 | public: |
31 | * We don't care of Device so you need to delete it | 24 | /** c'tor whichs create a new Manager |
32 | */ | 25 | * @param device is the device to use. Either a mac or blueZ device name |
33 | Manager( Device* dev ); | 26 | * |
34 | /** | 27 | */ |
35 | * c'tor | 28 | Manager( const QString &device ); |
36 | */ | ||
37 | Manager(); | ||
38 | ~Manager(); | ||
39 | 29 | ||
40 | /** Set the manager to control a new device | 30 | /** c'tor |
41 | * @param device the new device to control (hci0 ) | 31 | * @param dev The Device to be managed |
42 | */ | 32 | * We don't care of Device so you need to delete it |
43 | void setDevice( const QString& device ); | 33 | */ |
44 | /** | 34 | Manager( Device* dev ); |
45 | * Convience functions for setting a new device | ||
46 | */ | ||
47 | void setDevice( Device *dev ); | ||
48 | /** | ||
49 | * Wether or not a device is connected. The function | ||
50 | * is asynchron | ||
51 | * If device is empty it will take the currently managed | ||
52 | * device and see if it's up | ||
53 | * for Remote devices it will ping and see. | ||
54 | * @param either mac or hciX | ||
55 | */ | ||
56 | void isAvailable(const QString& device= QString::null ); | ||
57 | /** | ||
58 | * same as above | ||
59 | */ | ||
60 | void isAvailable(Device *dev ); | ||
61 | 35 | ||
62 | /** this searchs for devices reachable from the | 36 | /** |
63 | * currently managed device | 37 | * c'tor |
64 | * or from device if @param device is not empty | 38 | */ |
65 | */ | 39 | Manager(); |
66 | void searchDevices(const QString& device= QString::null ); | ||
67 | /** same as above | ||
68 | * | ||
69 | */ | ||
70 | void searchDevices(Device *d ); | ||
71 | 40 | ||
72 | /** | 41 | ~Manager(); |
73 | * This will add the service @param name | ||
74 | * to the sdpd daemon | ||
75 | * It will start the daemon if necessary | ||
76 | */ | ||
77 | void addService(const QString &name ); | ||
78 | /** | ||
79 | * This will add the services @param names | ||
80 | * to the sdpd daemon | ||
81 | * It will start the daemon if necessary | ||
82 | */ | ||
83 | void addServices( const QStringList& names ); | ||
84 | /** | ||
85 | * This removes a service from the sdps | ||
86 | */ | ||
87 | void removeService(const QString &name ); | ||
88 | /** | ||
89 | * Removes a list from the sdpd | ||
90 | */ | ||
91 | void removeServices(const QStringList& ); | ||
92 | 42 | ||
93 | /** | 43 | /** Set the manager to control a new device |
94 | * search for services on a remote device | 44 | * @param device the new device to control (hci0 ) |
95 | * | 45 | */ |
96 | */ | 46 | void setDevice( const QString& device ); |
97 | void searchServices( const QString& remDevice ); | 47 | |
98 | /** | 48 | /** |
99 | * search for services on a remote device | 49 | * Convience functions for setting a new device |
100 | */ | 50 | */ |
101 | void searchServices( const RemoteDevice& ); | 51 | void setDevice( Device *dev ); |
102 | /*static*/ QString toDevice( const QString& mac ); | 52 | |
103 | /*static*/ QString toMac( const QString &device ); | 53 | /** |
104 | 54 | * Wether or not a device is connected. The function | |
105 | signals: | 55 | * is asynchron |
106 | // device either mac or dev name | 56 | * If device is empty it will take the currently managed |
107 | // the first device is the device which you access | 57 | * device and see if it's up |
108 | void available( const QString& device, bool connected ); | 58 | * for Remote devices it will ping and see. |
109 | void addedService( const QString& service, bool added ); | 59 | * @param either mac or hciX |
110 | void removedService( const QString& service, bool removed ); | 60 | */ |
111 | void foundServices( const QString& device, Services::ValueList ); | 61 | void isAvailable(const QString& device= QString::null ); |
112 | void foundDevices( const QString& device, RemoteDevice::ValueList ); | 62 | |
63 | /** | ||
64 | * same as above | ||
65 | */ | ||
66 | void isAvailable(Device *dev ); | ||
67 | |||
68 | /** this searchs for devices reachable from the | ||
69 | * currently managed device | ||
70 | * or from device if @param device is not empty | ||
71 | */ | ||
72 | void searchDevices(const QString& device= QString::null ); | ||
73 | /** same as above | ||
74 | * | ||
75 | */ | ||
76 | void searchDevices(Device *d ); | ||
77 | |||
78 | /** | ||
79 | * This will add the service @param name | ||
80 | * to the sdpd daemon | ||
81 | * It will start the daemon if necessary | ||
82 | */ | ||
83 | void addService(const QString &name ); | ||
84 | |||
85 | /** | ||
86 | * This will add the services @param names | ||
87 | * to the sdpd daemon | ||
88 | * It will start the daemon if necessary | ||
89 | */ | ||
90 | void addServices( const QStringList& names ); | ||
91 | |||
92 | /** | ||
93 | * This removes a service from the sdps | ||
94 | */ | ||
95 | void removeService(const QString &name ); | ||
96 | |||
97 | /** | ||
98 | * Removes a list from the sdpd | ||
99 | */ | ||
100 | void removeServices(const QStringList& ); | ||
101 | |||
102 | /** | ||
103 | * search for services on a remote device | ||
104 | * | ||
105 | */ | ||
106 | void searchServices( const QString& remDevice ); | ||
107 | |||
108 | /** | ||
109 | * search for services on a remote device | ||
110 | */ | ||
111 | void searchServices( const RemoteDevice& ); | ||
112 | /*static*/ QString toDevice( const QString& mac ); | ||
113 | /*static*/ QString toMac( const QString &device ); | ||
114 | |||
115 | signals: | ||
116 | // device either mac or dev name | ||
117 | // the first device is the device which you access | ||
118 | void available( const QString& device, bool connected ); | ||
119 | void addedService( const QString& service, bool added ); | ||
120 | void removedService( const QString& service, bool removed ); | ||
121 | void foundServices( const QString& device, Services::ValueList ); | ||
122 | void foundDevices( const QString& device, RemoteDevice::ValueList ); | ||
123 | void connections( Connection::ValueList ); | ||
113 | 124 | ||
114 | private slots: | 125 | private slots: |
115 | void slotProcessExited(OProcess* ); | 126 | void slotProcessExited(OProcess* ); |
116 | void slotSDPExited(OProcess*); | 127 | |
117 | void slotSDPOut(OProcess*, char*, int); | 128 | void slotSDPExited(OProcess*); |
118 | void slotHCIExited(OProcess* ); | 129 | void slotSDPOut(OProcess*, char*, int); |
119 | void slotHCIOut(OProcess*, char*, int ); | 130 | |
120 | private: | 131 | void slotHCIExited(OProcess* ); |
121 | Services::ValueList parseSDPOutput( const QString& ); | 132 | void slotHCIOut(OProcess*, char*, int ); |
122 | RemoteDevice::ValueList parseHCIOutput( const QString& ); | 133 | |
123 | OProcess *m_hcitool; | 134 | void slotConnectionExited(OProcess* ); |
124 | OProcess *m_sdp; // not only one | 135 | void slotConnectionOutput(OProcess*, char*, int ); |
125 | QString m_device; | 136 | private: |
126 | QMap<QString, QString> m_out; | 137 | Services::ValueList parseSDPOutput( const QString& ); |
127 | QMap<QString, QString> m_devices; | 138 | RemoteDevice::ValueList parseHCIOutput( const QString& ); |
128 | }; | 139 | OProcess *m_hcitool; |
140 | OProcess *m_sdp; // not only one | ||
141 | QString m_device; | ||
142 | QMap<QString, QString> m_out; | ||
143 | QMap<QString, QString> m_devices; | ||
144 | QString m_hcitoolCon; | ||
145 | }; | ||
129 | }; | 146 | }; |
130 | 147 | ||
131 | #endif | 148 | #endif |