ZeusBase-Library  2.0.4
BluetoothSocket.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch)
3  *****************************************************************************
4  * Project : Zeus Base Library
5  * Module : BluetoothSocket
6  * Package : Zeus.ZeusBase.Net.Bluetooth
7  * Author : Benjamin Hadorn
8  * Date : 27.12.2011
9  * System : Zeus-Framework
10  *****************************************************************************
11  * Licence: *
12  * This library is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU Lesser General Public License as *
14  * published by the Free Software Foundation; either version *
15  * 2.1 of the License, or (at your option) any later version. *
16  * *
17  * This library is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU Lesser General Public License for more details. *
21  * *
22  * You should have received a copy of the GNU Lesser General Public *
23  * License along with this library; if not, write to the Free Software *
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA *
25  *****************************************************************************/
26 
27 /*****************************************************************************
28  * Changes:
29  * 27.12.2011 bha: created zeus 2.0
30  *****************************************************************************/
31 
32 #ifndef BluetoothSocketH
33 #define BluetoothSocketH
34 
35 #ifndef DISABLE_BLUETOOTH
36 
41 
43 
44 class TBTAddress;
45 
46 /****************************************************************************/
49 /****************************************************************************/
51 {
52  public:
54  TBluetoothSocket(TBTAddress& rAddress);
55  TBluetoothSocket(Int iFD, SOCKADDR_BTH& rSocketAddr);
56 
57  bool hasAuthentication() const;
58  bool hasEncryption() const;
59  void setAuthentication(bool bMode);
60  void setEncryption(bool bMode);
61 
62  //Methods of TAbstractSocket
63  virtual Retval connect();
64 
65  //Methods of IInputStream
66  virtual bool MQUALIFIER available() const{ return m_bConnected; }
67  virtual bool MQUALIFIER isEndReached() const { return !m_bConnected; }
68  virtual Retval MQUALIFIER read(char* pBuffer, Int iBufferSize, Int& rValidSize) const;
69  virtual Int MQUALIFIER readItem() const;
70  virtual Int8 MQUALIFIER readInt8(BOOL_ERRORRETVAL(pError)) const;
71  virtual Int16 MQUALIFIER readInt16(BOOL_ERRORRETVAL(pError)) const;
72  virtual Int32 MQUALIFIER readInt32(BOOL_ERRORRETVAL(pError)) const;
73  virtual Int64 MQUALIFIER readInt64(BOOL_ERRORRETVAL(pError)) const;
74  virtual Uint8 MQUALIFIER readUint8(BOOL_ERRORRETVAL(pError)) const;
75  virtual Uint16 MQUALIFIER readUint16(BOOL_ERRORRETVAL(pError)) const;
76  virtual Uint32 MQUALIFIER readUint32(BOOL_ERRORRETVAL(pError)) const;
77  virtual Uint64 MQUALIFIER readUint64(BOOL_ERRORRETVAL(pError)) const;
78  virtual Float64 MQUALIFIER readFloat64(BOOL_ERRORRETVAL(pError)) const;
79  virtual Float32 MQUALIFIER readFloat32(BOOL_ERRORRETVAL(pError)) const;
80  virtual bool MQUALIFIER readBool(BOOL_ERRORRETVAL(pError)) const;
81  virtual Retval MQUALIFIER readArray(IByteArray& rData) const;
82  virtual Retval MQUALIFIER readString(IString& rstrData) const;
83  virtual void MQUALIFIER close() { disconnect(); }
84  virtual void MQUALIFIER reset() {}
85  virtual bool MQUALIFIER skip(Int iBytes = 1);
86 
87  //Methods of IOutputStream
88  virtual Retval MQUALIFIER write(const char* pBuffer, Int iBufferSize);
89  virtual Retval MQUALIFIER writeInt8(Int8 cData);
90  virtual Retval MQUALIFIER writeInt16(Int16 sData);
91  virtual Retval MQUALIFIER writeInt32(Int32 lData);
92  virtual Retval MQUALIFIER writeInt64(const Int64& rldData);
93  virtual Retval MQUALIFIER writeUint8(Uint8 ucData);
94  virtual Retval MQUALIFIER writeUint16(Uint16 usData);
95  virtual Retval MQUALIFIER writeUint32(Uint32 ulData);
96  virtual Retval MQUALIFIER writeUint64(const Uint64& ruldData);
97  virtual Retval MQUALIFIER writeFloat32(Float32 fData);
98  virtual Retval MQUALIFIER writeFloat64(const Float64& rdData);
99  virtual Retval MQUALIFIER writeBool(bool bData);
100  virtual Retval MQUALIFIER writeArray(const IByteArray& rData);
101  virtual Retval MQUALIFIER writeString(const IString& rData);
102  virtual void MQUALIFIER flush() {}
103 
104  //Methods of IZUnknown
106 
107  protected:
108  virtual ~TBluetoothSocket();
109  virtual void openSocket();
110 
111  private:
112 };
113 
114 //INLINE METHODS
115 /**************************************************************************/
118 /**************************************************************************/
119 inline bool TBluetoothSocket::hasAuthentication() const
120 {
121  #if defined(ENABLE_WIN32_BLUETOOTH)
122  return TAbstractSocket::getBoolSocketOption(m_iSocketFD, SO_BTH_AUTHENTICATE, SOL_RFCOMM);
123  #elif defined(ENABLE_BLUEZ_BLUETOOTH)
124  return TAbstractSocket::getBoolSocketOption(m_iSocketFD, RFCOMM_LM_AUTH, SOL_RFCOMM);
125  #else
126  return false;
127  #endif
128 }
129 
130 /**************************************************************************/
133 /**************************************************************************/
134 inline bool TBluetoothSocket::hasEncryption() const
135 {
136  #if defined(ENABLE_WIN32_BLUETOOTH)
137  return TAbstractSocket::getBoolSocketOption(m_iSocketFD, SO_BTH_ENCRYPT, SOL_RFCOMM);
138  #elif defined(ENABLE_BLUEZ_BLUETOOTH)
139  return TAbstractSocket::getBoolSocketOption(m_iSocketFD, RFCOMM_LM_ENCRYPT, SOL_RFCOMM);
140  #else
141  return false;
142  #endif
143 }
144 
145 /**************************************************************************/
148 /**************************************************************************/
149 inline void TBluetoothSocket::setAuthentication(bool bMode)
150 {
151  #if defined(ENABLE_WIN32_BLUETOOTH)
152  TAbstractSocket::setBoolSocketOption(m_iSocketFD, SO_BTH_AUTHENTICATE, SOL_RFCOMM, bMode);
153  #elif defined(ENABLE_BLUEZ_BLUETOOTH)
154  TAbstractSocket::setBoolSocketOption(m_iSocketFD, RFCOMM_LM_AUTH, SOL_RFCOMM, bMode);
155  #else
156  //no bluetooth available
157  #endif
158 }
159 
160 /**************************************************************************/
163 /**************************************************************************/
164 inline void TBluetoothSocket::setEncryption(bool bMode)
165 {
166  #if defined(ENABLE_WIN32_BLUETOOTH)
167  TAbstractSocket::setBoolSocketOption(m_iSocketFD, SO_BTH_ENCRYPT, SOL_RFCOMM, bMode);
168  #elif defined(ENABLE_BLUEZ_BLUETOOTH)
169  TAbstractSocket::setBoolSocketOption(m_iSocketFD, RFCOMM_LM_ENCRYPT, SOL_RFCOMM, bMode);
170  #else
171  //no bluetooth available
172  #endif
173 }
174 
175 /***************************************************************************/
178 /***************************************************************************/
179 inline Uint8 MQUALIFIER TBluetoothSocket::readUint8(bool* pError) const
180 {
181  return static_cast<Uint8>(readInt8(pError));
182 }
183 
184 /***************************************************************************/
187 /***************************************************************************/
188 inline Uint16 MQUALIFIER TBluetoothSocket::readUint16(bool* pError) const
189 {
190  return static_cast<Uint16>(readInt16(pError));
191 }
192 
193 /***************************************************************************/
196 /***************************************************************************/
197 inline Uint32 MQUALIFIER TBluetoothSocket::readUint32(bool* pError) const
198 {
199  return static_cast<Uint32>(readInt32(pError));
200 }
201 
202 /***************************************************************************/
205 /***************************************************************************/
206 inline Uint64 MQUALIFIER TBluetoothSocket::readUint64(bool* pError) const
207 {
208  return static_cast<Uint64>(readInt64(pError));
209 }
210 
211 /**************************************************************************/
214 /**************************************************************************/
215 inline bool MQUALIFIER TBluetoothSocket::readBool(bool* pError) const
216 {
217  return (readInt8(pError) != 0 );
218 }
219 
220 /***************************************************************************/
223 /***************************************************************************/
224 inline Retval MQUALIFIER TBluetoothSocket::writeUint8(Uint8 ucData)
225 {
226  return writeInt8(static_cast<Int8>(ucData));
227 }
228 
229 /***************************************************************************/
232 /***************************************************************************/
233 inline Retval MQUALIFIER TBluetoothSocket::writeUint16(Uint16 usData)
234 {
235  return writeInt16(static_cast<Int16>(usData));
236 }
237 
238 /***************************************************************************/
241 /***************************************************************************/
242 inline Retval MQUALIFIER TBluetoothSocket::writeUint32(Uint32 ulData)
243 {
244  return writeInt32(static_cast<Int32>(ulData));
245 }
246 
247 /***************************************************************************/
250 /***************************************************************************/
251 inline Retval MQUALIFIER TBluetoothSocket::writeUint64(const Uint64& ruldData)
252 {
253  return writeInt64(static_cast<Int64>(ruldData));
254 }
255 
256 /***************************************************************************/
259 /***************************************************************************/
260 inline Retval MQUALIFIER TBluetoothSocket::writeBool(bool bData)
261 {
262  return writeInt8(static_cast<Int8>(bData));
263 }
264 
266 
267 
268 #endif // #ifndef DISABLE_BLUETOOTH
269 
270 #endif
271 
#define END_NAMESPACE_Zeus
Definition: PlatformDefines.hpp:96
#define SO_BTH_AUTHENTICATE
Definition: bcb6/ws2bth.h:73
#define zeusbase_class
Definition: PlatformDefines.hpp:165
#define SO_BTH_ENCRYPT
Definition: bcb6/ws2bth.h:74
virtual bool MQUALIFIER isEndReached() const
Definition: BluetoothSocket.h:67
#define SOL_RFCOMM
Definition: bcb6/ws2bth.h:66
Definition: IOutputStream.hpp:50
Definition: BluetoothSocket.h:50
Definition: BTDefines.hpp:88
short Int16
Definition: PlatformDefines.hpp:215
#define MQUALIFIER
Definition: LinuxPlatform.hpp:64
unsigned short Uint16
Definition: PlatformDefines.hpp:219
unsigned long long Uint64
Definition: PlatformDefines.hpp:252
#define BEGIN_NAMESPACE_Zeus
Definition: PlatformDefines.hpp:95
long Int32
Definition: PlatformDefines.hpp:237
virtual bool MQUALIFIER available() const
Definition: BluetoothSocket.h:66
Definition: IInputStream.hpp:50
#define BOOL_ERRORRETVAL(c)
Definition: RetvalDefines.hpp:111
long long Int64
Definition: PlatformDefines.hpp:251
unsigned long Uint32
Definition: PlatformDefines.hpp:241
unsigned char Uint8
Definition: PlatformDefines.hpp:212
virtual void MQUALIFIER close()
Definition: BluetoothSocket.h:83
char Int8
Definition: PlatformDefines.hpp:208
float Float32
Definition: PlatformDefines.hpp:270
Definition: BTAddress.h:48
virtual void MQUALIFIER flush()
Definition: BluetoothSocket.h:102
Definition: AbstractSocket.h:74
double Float64
Definition: PlatformDefines.hpp:274
virtual void MQUALIFIER reset()
Definition: BluetoothSocket.h:84
#define MEMORY_MANAGER_DECL
Definition: IZUnknownImplHelper.hpp:44
Definition: IString.hpp:48


Written by Benjamin Hadorn http://www.xatlantis.ch.
Last change made on Tue Sep 13 2016 22:30:32