• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "packet/byte_inserter.h"
18 
19 #include "os/log.h"
20 
21 namespace bluetooth {
22 namespace packet {
23 
ByteInserter(std::vector<uint8_t> & vector)24 ByteInserter::ByteInserter(std::vector<uint8_t>& vector) : std::back_insert_iterator<std::vector<uint8_t>>(vector) {}
25 
~ByteInserter()26 ByteInserter::~ByteInserter() {
27   ASSERT(registered_observers_.empty());
28 }
29 
RegisterObserver(const ByteObserver & observer)30 void ByteInserter::RegisterObserver(const ByteObserver& observer) {
31   registered_observers_.push_back(observer);
32 }
33 
UnregisterObserver()34 ByteObserver ByteInserter::UnregisterObserver() {
35   ByteObserver observer = registered_observers_.back();
36   registered_observers_.pop_back();
37   return observer;
38 }
39 
on_byte(uint8_t byte)40 void ByteInserter::on_byte(uint8_t byte) {
41   for (auto& observer : registered_observers_) {
42     observer.OnByte(byte);
43   }
44 }
45 
insert_byte(uint8_t byte)46 void ByteInserter::insert_byte(uint8_t byte) {
47   on_byte(byte);
48   std::back_insert_iterator<std::vector<uint8_t>>::operator=(byte);
49 }
50 
51 }  // namespace packet
52 }  // namespace bluetooth
53