bin/pc: Mark non-returning function as void
[haiku.git] / headers / os / bluetooth / bdaddrUtils.h
blob0b1a2bf1a4080b8be1116df0521c951168e3476f
1 /*
2 * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3 * Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com
4 * All rights reserved. Distributed under the terms of the MIT License.
5 */
6 #ifndef _BDADDR_UTILS_H
7 #define _BDADDR_UTILS_H
9 #include <stdio.h>
10 #include <string.h>
12 #include <String.h>
14 #include <bluetooth/bluetooth.h>
16 namespace Bluetooth {
18 class bdaddrUtils {
20 public:
21 static inline bdaddr_t NullAddress()
23 return ((bdaddr_t) {{0, 0, 0, 0, 0, 0}});
27 static inline bdaddr_t LocalAddress()
29 return ((bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}});
33 static inline bdaddr_t BroadcastAddress()
35 return ((bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}});
39 static bool Compare(const bdaddr_t& ba1, const bdaddr_t& ba2)
41 return (memcmp(&ba1, &ba2, sizeof(bdaddr_t)) == 0);
45 static void Copy(bdaddr_t& dst, const bdaddr_t& src)
47 memcpy(&dst, &src, sizeof(bdaddr_t));
50 static BString ToString(const bdaddr_t bdaddr)
52 BString str;
54 str.SetToFormat("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",bdaddr.b[5],
55 bdaddr.b[4], bdaddr.b[3], bdaddr.b[2], bdaddr.b[1],
56 bdaddr.b[0]);
57 return str;
61 static bdaddr_t FromString(const char * addr)
63 uint8 b0, b1, b2, b3, b4, b5;
65 if (addr != NULL) {
66 size_t count = sscanf(addr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
67 &b5, &b4, &b3, &b2, &b1, &b0);
69 if (count == 6)
70 return ((bdaddr_t) {{b0, b1, b2, b3, b4, b5}});
73 return NullAddress();
81 #ifndef _BT_USE_EXPLICIT_NAMESPACE
82 using Bluetooth::bdaddrUtils;
83 #endif
86 #endif // _BDADDR_UTILS_H