nidas  v1.2-1520
BluetoothRFCommSocketAddress.h
Go to the documentation of this file.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2 // vim: set shiftwidth=4 softtabstop=4 expandtab:
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2010, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
13  **
14  ** This program is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 
27 #include <nidas/Config.h>
28 
29 #ifdef HAVE_BLUETOOTH_RFCOMM_H
30 
31 #ifndef NIDAS_UTIL_BLUETOOTHRFCOMMSOCKETADDRESS
32 #define NIDAS_UTIL_BLUETOOTHRFCOMMSOCKETADDRESS
33 
34 #include "SocketAddress.h"
35 #include "BluetoothAddress.h"
36 #include <bluetooth/rfcomm.h>
37 
38 namespace nidas { namespace util {
39 
43 class BluetoothRFCommSocketAddress: public SocketAddress {
44 public:
45 
46  BluetoothRFCommSocketAddress();
47 
51  BluetoothRFCommSocketAddress(int channel);
52 
56  BluetoothRFCommSocketAddress(const std::string& host,int channel);
57 
61  BluetoothRFCommSocketAddress(const BluetoothAddress& addr,int channel);
62 
66  BluetoothRFCommSocketAddress(const struct sockaddr_rc* sockaddr);
67 
71  BluetoothRFCommSocketAddress(const BluetoothRFCommSocketAddress&);
72 
76  BluetoothRFCommSocketAddress& operator=(const BluetoothRFCommSocketAddress& x);
77 
81  BluetoothRFCommSocketAddress* clone() const;
82 
86  int getFamily() const { return AF_BLUETOOTH; }
87 
91  BluetoothAddress getBluetoothAddress() const {
92  return BluetoothAddress(&_sockaddr.rc_bdaddr);
93  }
94 
98  int getPort() const { return _sockaddr.rc_channel; }
99 
106  struct sockaddr* getSockAddrPtr() { return (struct sockaddr*) &_sockaddr; }
107 
111  const struct sockaddr* getConstSockAddrPtr() const
112  {
113  return (const struct sockaddr*) &_sockaddr;
114  }
115 
116  socklen_t getSockAddrLen() const { return sizeof(_sockaddr); }
117 
121  std::string toString() const;
122 
126  std::string toAddressString() const;
127 
132  bool operator < (const BluetoothRFCommSocketAddress& x) const;
133 
137  bool operator == (const BluetoothRFCommSocketAddress& x) const;
138 
139 private:
140  struct sockaddr_rc _sockaddr;
141 };
142 
143 }} // namespace nidas namespace util
144 
145 #endif
146 #endif
bool operator==(const BitArray &x, const BitArray &y)
Definition: BitArray.cc:176