author | wimpie <wimpie> | 2005-01-04 01:42:25 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2005-01-04 01:42:25 (UTC) |
commit | 2487b0a05f502e7410715460f390cc80e7e76fd9 (patch) (side-by-side diff) | |
tree | 430dce90a1bdff8eb85cbf1004db094ab6653ab9 /noncore/settings/networksettings2/opietooth2/OTDeviceAddress.h | |
parent | e2094d408c9102f8866aafbe725a65f25fdef063 (diff) | |
download | opie-2487b0a05f502e7410715460f390cc80e7e76fd9.zip opie-2487b0a05f502e7410715460f390cc80e7e76fd9.tar.gz opie-2487b0a05f502e7410715460f390cc80e7e76fd9.tar.bz2 |
*** empty log message ***
Diffstat (limited to 'noncore/settings/networksettings2/opietooth2/OTDeviceAddress.h') (more/less context) (ignore 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 @@ +//-*-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 OTDEVICEADDRESS_H +#define OTDEVICEADDRESS_H + +#include <qstring.h> +#include <bluezlib.h> + +namespace Opietooth2 { + +/** Represents a Bluetooth device address. + * This class allows easy conversion of Bluetooth addresses + * from and to strings. It also works with the bdaddr_t type + * used by BlueZ. + * The class offers a comparsion and less-than operator, so + * that it can be used a key in an STL map or similar. + * The string conversion functions of BlueZ are used internally, + * so the string format is the same than for BlueZ's ba2str(). + */ +class OTDeviceAddress { + +public: + + /** Default constructor. + The resulting address is equal to DeviceAddress::invalid. + */ + OTDeviceAddress(); + + /** Initialize the object with a BlueZ bdaddr_t. + @param bdaddr address + @param networkbyteorder if true, bdaddr is assumed to be in + network byte order and converted to host byte order first. + */ + explicit OTDeviceAddress( const bdaddr_t& bdaddr, + bool networkbyteorder = false + ); + + /** Initializes the object with an address given as a string. + The string must be in a format which is understood by the + BlueZ str2ba function, like 00:61:58:4C:E6:AD. Case doesn't matter. + @param s address string + */ + explicit OTDeviceAddress(const QString& s); + + /** convert the address to a string. + @return address string + */ + QString toString() const; + + /** Converts the DeviceAddress into a BlueZ bdaddr_t. + @param networkbyteorder if true, the address is returned + in network byte order. + @return the address as bdaddr_t + */ + inline const bdaddr_t & getBDAddr( void ) const + { return BDaddr; } + bdaddr_t getBDAddrInNetworkByteOrder() const; + void setBDAddr( const bdaddr_t& bdaddr, + bool networkbyteorder = false + ); + + /** Less-than-operator. + Mainly there to use DeviceAddress inside STL containers, + like STL sets or as a key in a STL map. + @param b the DeviceAddress to compare to (right hand side) + @return true if this < b, false otherwise. + */ + bool operator<(const OTDeviceAddress& b) const; + + /** Equality operator. + Tests two device addresses for equality. + @param b the DeviceAddress to compare to (right hand side) + @return true if this and b have the same address or + if both are invalid, false otherwise + */ + bool operator==(const OTDeviceAddress& b) const; + + inline bool operator!=(const OTDeviceAddress& b) const + { return ! ( *this == b ); } + + /** The address 00:00:00:FF:FF:FF */ + static const OTDeviceAddress local; + + /** The address 00:00:00:00:00:00 */ + static const OTDeviceAddress any; + + /** An address tagged as invalid */ + static const OTDeviceAddress invalid; + +protected: + + bdaddr_t BDaddr; + bool IsValid; + +}; + +} + +#endif |