Diffstat (limited to 'noncore/settings/networksettings2/opietooth2/OTDeviceAddress.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/opietooth2/OTDeviceAddress.h | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/opietooth2/OTDeviceAddress.h b/noncore/settings/networksettings2/opietooth2/OTDeviceAddress.h new file mode 100644 index 0000000..8395f37 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/OTDeviceAddress.h | |||
@@ -0,0 +1,108 @@ | |||
1 | //-*-c++-*- | ||
2 | /*************************************************************************** | ||
3 | * Copyright (C) 2003 by Fred Schaettgen * | ||
4 | * kdebluetooth@0xF.de * | ||
5 | * * | ||
6 | * This program is free software; you can redistribute it and/or modify * | ||
7 | * it under the terms of the GNU General Public License as published by * | ||
8 | * the Free Software Foundation; either version 2 of the License, or * | ||
9 | * (at your option) any later version. * | ||
10 | ***************************************************************************/ | ||
11 | |||
12 | #ifndef OTDEVICEADDRESS_H | ||
13 | #define OTDEVICEADDRESS_H | ||
14 | |||
15 | #include <qstring.h> | ||
16 | #include <bluezlib.h> | ||
17 | |||
18 | namespace Opietooth2 { | ||
19 | |||
20 | /** Represents a Bluetooth device address. | ||
21 | * This class allows easy conversion of Bluetooth addresses | ||
22 | * from and to strings. It also works with the bdaddr_t type | ||
23 | * used by BlueZ. | ||
24 | * The class offers a comparsion and less-than operator, so | ||
25 | * that it can be used a key in an STL map or similar. | ||
26 | * The string conversion functions of BlueZ are used internally, | ||
27 | * so the string format is the same than for BlueZ's ba2str(). | ||
28 | */ | ||
29 | class OTDeviceAddress { | ||
30 | |||
31 | public: | ||
32 | |||
33 | /** Default constructor. | ||
34 | The resulting address is equal to DeviceAddress::invalid. | ||
35 | */ | ||
36 | OTDeviceAddress(); | ||
37 | |||
38 | /** Initialize the object with a BlueZ bdaddr_t. | ||
39 | @param bdaddr address | ||
40 | @param networkbyteorder if true, bdaddr is assumed to be in | ||
41 | network byte order and converted to host byte order first. | ||
42 | */ | ||
43 | explicit OTDeviceAddress( const bdaddr_t& bdaddr, | ||
44 | bool networkbyteorder = false | ||
45 | ); | ||
46 | |||
47 | /** Initializes the object with an address given as a string. | ||
48 | The string must be in a format which is understood by the | ||
49 | BlueZ str2ba function, like 00:61:58:4C:E6:AD. Case doesn't matter. | ||
50 | @param s address string | ||
51 | */ | ||
52 | explicit OTDeviceAddress(const QString& s); | ||
53 | |||
54 | /** convert the address to a string. | ||
55 | @return address string | ||
56 | */ | ||
57 | QString toString() const; | ||
58 | |||
59 | /** Converts the DeviceAddress into a BlueZ bdaddr_t. | ||
60 | @param networkbyteorder if true, the address is returned | ||
61 | in network byte order. | ||
62 | @return the address as bdaddr_t | ||
63 | */ | ||
64 | inline const bdaddr_t & getBDAddr( void ) const | ||
65 | { return BDaddr; } | ||
66 | bdaddr_t getBDAddrInNetworkByteOrder() const; | ||
67 | void setBDAddr( const bdaddr_t& bdaddr, | ||
68 | bool networkbyteorder = false | ||
69 | ); | ||
70 | |||
71 | /** Less-than-operator. | ||
72 | Mainly there to use DeviceAddress inside STL containers, | ||
73 | like STL sets or as a key in a STL map. | ||
74 | @param b the DeviceAddress to compare to (right hand side) | ||
75 | @return true if this < b, false otherwise. | ||
76 | */ | ||
77 | bool operator<(const OTDeviceAddress& b) const; | ||
78 | |||
79 | /** Equality operator. | ||
80 | Tests two device addresses for equality. | ||
81 | @param b the DeviceAddress to compare to (right hand side) | ||
82 | @return true if this and b have the same address or | ||
83 | if both are invalid, false otherwise | ||
84 | */ | ||
85 | bool operator==(const OTDeviceAddress& b) const; | ||
86 | |||
87 | inline bool operator!=(const OTDeviceAddress& b) const | ||
88 | { return ! ( *this == b ); } | ||
89 | |||
90 | /** The address 00:00:00:FF:FF:FF */ | ||
91 | static const OTDeviceAddress local; | ||
92 | |||
93 | /** The address 00:00:00:00:00:00 */ | ||
94 | static const OTDeviceAddress any; | ||
95 | |||
96 | /** An address tagged as invalid */ | ||
97 | static const OTDeviceAddress invalid; | ||
98 | |||
99 | protected: | ||
100 | |||
101 | bdaddr_t BDaddr; | ||
102 | bool IsValid; | ||
103 | |||
104 | }; | ||
105 | |||
106 | } | ||
107 | |||
108 | #endif | ||