BTRFS: Reimplement TreeIterator, add some error checks and remove redundancies.
[haiku.git] / headers / os / bluetooth / LinkKeyUtils.h
blob56b7d914dd040ce184fa04140940329f482a2157
1 /*
2 * Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5 #ifndef _LINKKEY_UTILS_H
6 #define _LINKKEY_UTILS_H
8 #include <stdio.h>
10 #include <bluetooth/bluetooth.h>
13 namespace Bluetooth {
15 class LinkKeyUtils {
16 public:
17 static bool Compare(linkkey_t* lk1, linkkey_t* lk2)
19 return memcmp(lk1, lk2, sizeof(linkkey_t)) == 0;
22 static linkkey_t NullKey()
24 return (linkkey_t){{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
27 static BString ToString(const linkkey_t lk)
29 BString str;
31 str.SetToFormat("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:"
32 "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
33 lk.l[0], lk.l[1], lk.l[2], lk.l[3], lk.l[4], lk.l[5],
34 lk.l[6], lk.l[7], lk.l[8], lk.l[9], lk.l[10], lk.l[11],
35 lk.l[12], lk.l[13], lk.l[14], lk.l[15]);
37 return str;
40 static linkkey_t FromString(const char *lkstr)
42 if (lkstr != NULL) {
43 uint8 l0, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15;
44 size_t count = sscanf(lkstr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:"
45 "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhxs", &l0, &l1, &l2, &l3,
46 &l4, &l5, &l6, &l7, &l8, &l9, &l10, &l11, &l12, &l13,
47 &l14, &l15);
49 if (count == 16) {
50 return (linkkey_t){{l0, l1, l2, l3, l4, l5, l6, l7, l8,
51 l9, l10, l11, l12, l13, l14, l15}};
55 return NullKey();
61 #ifndef _BT_USE_EXPLICIT_NAMESPACE
62 using Bluetooth::LinkKeyUtils;
63 #endif
65 #endif // _LINKKEY_UTILS_H