Diffstat (limited to 'noncore/settings/networksettings2/opietooth2/OTDeviceAddress.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/opietooth2/OTDeviceAddress.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/opietooth2/OTDeviceAddress.cpp b/noncore/settings/networksettings2/opietooth2/OTDeviceAddress.cpp new file mode 100644 index 0000000..7fbfaf4 --- a/dev/null +++ b/noncore/settings/networksettings2/opietooth2/OTDeviceAddress.cpp | |||
@@ -0,0 +1,110 @@ | |||
1 | //-*-c++-*- | ||
2 | /*************************************************************************** | ||
3 | * Copyright (C) 2003 by Fred Schaettgen * | ||
4 | * kdebluetooth@schaettgen.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 | #include <string.h> | ||
13 | #include <bluezlib.h> | ||
14 | #include <opie2/odebug.h> | ||
15 | |||
16 | #include <OTDeviceAddress.h> | ||
17 | |||
18 | using namespace Opietooth2; | ||
19 | |||
20 | //const bdaddr_t OTDeviceAddress::bdaddr_any = {{0,0,0,0,0,0}}; | ||
21 | //const bdaddr_t OTDeviceAddress::bdaddr_local = {{0, 0, 0, 0xff, 0xff, 0xff}}; | ||
22 | |||
23 | const OTDeviceAddress OTDeviceAddress::invalid = | ||
24 | OTDeviceAddress(); | ||
25 | const OTDeviceAddress OTDeviceAddress::any = | ||
26 | OTDeviceAddress("00:00:00:00:00:00"); | ||
27 | const OTDeviceAddress OTDeviceAddress::local = | ||
28 | OTDeviceAddress("00:00:00:FF:FF:FF"); | ||
29 | |||
30 | OTDeviceAddress::OTDeviceAddress() { | ||
31 | |||
32 | IsValid = false; | ||
33 | memset( &BDaddr, 0, sizeof( BDaddr ) ); | ||
34 | } | ||
35 | |||
36 | OTDeviceAddress::OTDeviceAddress( const bdaddr_t& bdaddr, | ||
37 | bool networkbyteorder) { | ||
38 | setBDAddr( bdaddr, networkbyteorder ); | ||
39 | } | ||
40 | |||
41 | OTDeviceAddress::OTDeviceAddress(const QString& s) { | ||
42 | |||
43 | bdaddr_t a; | ||
44 | int ret = str2ba(s.latin1(), &a); | ||
45 | if (ret==0) { | ||
46 | IsValid = true; | ||
47 | bacpy( &BDaddr, &a ); | ||
48 | } else { | ||
49 | IsValid = false; | ||
50 | bacpy( &BDaddr, &(OTDeviceAddress::invalid.getBDAddr()) ) ; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | QString OTDeviceAddress::toString() const { | ||
55 | char addrbuf[20]; | ||
56 | ba2str(&BDaddr, addrbuf); | ||
57 | return QString(addrbuf); | ||
58 | |||
59 | } | ||
60 | |||
61 | void OTDeviceAddress::setBDAddr( const bdaddr_t& bdaddr, | ||
62 | bool networkbyteorder) { | ||
63 | if (networkbyteorder) { | ||
64 | baswap(&BDaddr, &bdaddr); | ||
65 | } else { | ||
66 | bacpy( &BDaddr, &bdaddr ); | ||
67 | } | ||
68 | IsValid = true; | ||
69 | } | ||
70 | |||
71 | bdaddr_t OTDeviceAddress::getBDAddrInNetworkByteOrder(void) const { | ||
72 | bdaddr_t ret; | ||
73 | baswap(&ret, &BDaddr); | ||
74 | return ret; | ||
75 | } | ||
76 | |||
77 | bool OTDeviceAddress::operator==(const OTDeviceAddress& b) const { | ||
78 | if ( ! IsValid && ! b.IsValid ) | ||
79 | return true; | ||
80 | return memcmp( &BDaddr, &(b.BDaddr), sizeof( b.BDaddr ) ) == 0; | ||
81 | } | ||
82 | |||
83 | bool OTDeviceAddress::operator<(const OTDeviceAddress& b) const { | ||
84 | if ( ! IsValid && ! b.IsValid ) | ||
85 | return false; | ||
86 | else if ( ! IsValid && b.IsValid ) | ||
87 | return false; | ||
88 | else if ( IsValid && ! b.IsValid ) | ||
89 | return true; | ||
90 | |||
91 | if (BDaddr.b[5] != b.BDaddr.b[5]) | ||
92 | return (BDaddr.b[5] < b.BDaddr.b[5]); | ||
93 | |||
94 | if (BDaddr.b[4] != b.BDaddr.b[4]) | ||
95 | return (BDaddr.b[4] < b.BDaddr.b[4]); | ||
96 | |||
97 | if (BDaddr.b[3] != b.BDaddr.b[3]) | ||
98 | return (BDaddr.b[3] < b.BDaddr.b[3]); | ||
99 | |||
100 | if (BDaddr.b[2] != b.BDaddr.b[2]) | ||
101 | return (BDaddr.b[2] < b.BDaddr.b[2]); | ||
102 | |||
103 | if (BDaddr.b[1] != b.BDaddr.b[1]) | ||
104 | return (BDaddr.b[1] < b.BDaddr.b[1]); | ||
105 | |||
106 | if (BDaddr.b[0] != b.BDaddr.b[0]) | ||
107 | return (BDaddr.b[0] < b.BDaddr.b[0]); | ||
108 | |||
109 | return false; | ||
110 | } | ||