blob: 4c37ebf26992ed1b9cf22d9c007603483d715be7 [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
Chienyuandb55f312019-10-31 14:01:28 +080023namespace bluetooth {
24namespace types {
25
Myles Watson6c252872018-11-21 16:24:52 -080026/** Bluetooth Class of Device */
27class ClassOfDevice final {
28 public:
29 static constexpr unsigned int kLength = 3;
30
31 uint8_t cod[kLength];
32
33 ClassOfDevice() = default;
34 ClassOfDevice(const uint8_t (&class_of_device)[kLength]);
35
36 bool operator==(const ClassOfDevice& rhs) const {
37 return (std::memcmp(cod, rhs.cod, sizeof(cod)) == 0);
38 }
39
40 std::string ToString() const;
41
42 // Converts |string| to ClassOfDevice and places it in |to|. If |from| does
43 // not represent a Class of Device, |to| is not modified and this function
44 // returns false. Otherwise, it returns true.
45 static bool FromString(const std::string& from, ClassOfDevice& to);
46
47 // Copies |from| raw Class of Device octets to the local object.
48 // Returns the number of copied octets (always ClassOfDevice::kLength)
49 size_t FromOctets(const uint8_t* from);
50
51 static bool IsValid(const std::string& class_of_device);
52};
53
54inline std::ostream& operator<<(std::ostream& os, const ClassOfDevice& c) {
55 os << c.ToString();
56 return os;
57}
Chienyuandb55f312019-10-31 14:01:28 +080058
59} // namespace types
60} // namespace bluetooth
61
62using ::bluetooth::types::ClassOfDevice; // TODO, remove