Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OTDeviceAddress.cpp

Go to the documentation of this file.
00001 //-*-c++-*-
00002 /***************************************************************************
00003  *   Copyright (C) 2003 by Fred Schaettgen                                 *
00004  *   kdebluetooth@schaettgen.de                                            *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  ***************************************************************************/
00011 
00012 #include <string.h>
00013 #include <bluezlib.h>
00014 #include <opie2/odebug.h>
00015 
00016 #include <OTDeviceAddress.h>
00017 
00018 using namespace Opietooth2;
00019 
00020 //const bdaddr_t OTDeviceAddress::bdaddr_any = {{0,0,0,0,0,0}};
00021 //const bdaddr_t OTDeviceAddress::bdaddr_local = {{0, 0, 0, 0xff, 0xff, 0xff}};
00022 
00023 const OTDeviceAddress OTDeviceAddress::invalid = 
00024                 OTDeviceAddress();
00025 const OTDeviceAddress OTDeviceAddress::any = 
00026                 OTDeviceAddress("00:00:00:00:00:00");
00027 const OTDeviceAddress OTDeviceAddress::local =  
00028                 OTDeviceAddress("00:00:00:FF:FF:FF");
00029 
00030 OTDeviceAddress::OTDeviceAddress() {
00031 
00032     IsValid = false;
00033     memset( &BDaddr, 0, sizeof( BDaddr ) );
00034 }
00035 
00036 OTDeviceAddress::OTDeviceAddress( const bdaddr_t& bdaddr, 
00037                                   bool networkbyteorder) {
00038     setBDAddr( bdaddr, networkbyteorder );
00039 }
00040 
00041 OTDeviceAddress::OTDeviceAddress(const QString& s) {
00042 
00043     bdaddr_t a;
00044     int ret = str2ba(s.latin1(), &a);
00045     if (ret==0) {
00046         IsValid = true;
00047         bacpy( &BDaddr, &a );
00048     } else {
00049         IsValid = false;
00050         bacpy( &BDaddr, &(OTDeviceAddress::invalid.getBDAddr()) ) ;
00051     }
00052 }
00053 
00054 QString OTDeviceAddress::toString() const {
00055     char addrbuf[20];
00056     ba2str(&BDaddr, addrbuf);
00057     return QString(addrbuf);
00058 
00059 }
00060 
00061 void OTDeviceAddress::setBDAddr( const bdaddr_t& bdaddr, 
00062                                  bool networkbyteorder) {
00063     if (networkbyteorder) {
00064         baswap(&BDaddr, &bdaddr);
00065     } else {
00066         bacpy( &BDaddr, &bdaddr );
00067     }
00068     IsValid = true;
00069 }
00070 
00071 bdaddr_t OTDeviceAddress::getBDAddrInNetworkByteOrder(void) const {
00072     bdaddr_t ret;
00073     baswap(&ret, &BDaddr);
00074     return ret;
00075 }
00076 
00077 bool OTDeviceAddress::operator==(const OTDeviceAddress& b) const {
00078     if ( ! IsValid && ! b.IsValid )
00079         return true;
00080     return memcmp( &BDaddr, &(b.BDaddr), sizeof( b.BDaddr ) ) == 0;
00081 }
00082 
00083 bool OTDeviceAddress::operator<(const OTDeviceAddress& b) const {
00084     if ( ! IsValid &&  ! b.IsValid )
00085         return false;
00086     else if ( ! IsValid && b.IsValid )
00087         return false;
00088     else if ( IsValid && ! b.IsValid )
00089         return true;
00090 
00091     if (BDaddr.b[5] != b.BDaddr.b[5]) 
00092         return (BDaddr.b[5] < b.BDaddr.b[5]);
00093 
00094     if (BDaddr.b[4] != b.BDaddr.b[4]) 
00095         return (BDaddr.b[4] < b.BDaddr.b[4]);
00096 
00097     if (BDaddr.b[3] != b.BDaddr.b[3]) 
00098         return (BDaddr.b[3] < b.BDaddr.b[3]);
00099 
00100     if (BDaddr.b[2] != b.BDaddr.b[2]) 
00101         return (BDaddr.b[2] < b.BDaddr.b[2]);
00102 
00103     if (BDaddr.b[1] != b.BDaddr.b[1]) 
00104         return (BDaddr.b[1] < b.BDaddr.b[1]);
00105 
00106     if (BDaddr.b[0] != b.BDaddr.b[0]) 
00107         return (BDaddr.b[0] < b.BDaddr.b[0]);
00108 
00109     return false;
00110 }

Generated on Sat Nov 5 16:17:55 2005 for OPIE by  doxygen 1.4.2