blob: 8c2ab37e8de8a75c94469613b87a0f36c78ac8a4 [file] [log] [blame]
Myles Watson6c252872018-11-21 16:24:52 -08001/******************************************************************************
2 *
3 * Copyright 2018 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19#pragma once
20
21#include <string>
22
23/** Bluetooth Class of Device */
24class ClassOfDevice final {
25 public:
26 static constexpr unsigned int kLength = 3;
27
28 uint8_t cod[kLength];
29
30 ClassOfDevice() = default;
31 ClassOfDevice(const uint8_t (&class_of_device)[kLength]);
32
33 bool operator==(const ClassOfDevice& rhs) const {
34 return (std::memcmp(cod, rhs.cod, sizeof(cod)) == 0);
35 }
36
37 std::string ToString() const;
38
39 // Converts |string| to ClassOfDevice and places it in |to|. If |from| does
40 // not represent a Class of Device, |to| is not modified and this function
41 // returns false. Otherwise, it returns true.
42 static bool FromString(const std::string& from, ClassOfDevice& to);
43
44 // Copies |from| raw Class of Device octets to the local object.
45 // Returns the number of copied octets (always ClassOfDevice::kLength)
46 size_t FromOctets(const uint8_t* from);
47
48 static bool IsValid(const std::string& class_of_device);
49};
50
51inline std::ostream& operator<<(std::ostream& os, const ClassOfDevice& c) {
52 os << c.ToString();
53 return os;
54}