• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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 #pragma once
18 
19 #include <algorithm>
20 #include <cstdint>
21 
22 #include "hci/hci_packets.h"
23 #include "model/controller/connected_isochronous_stream.h"
24 
25 namespace rootcanal {
26 
27 class GroupParameters {
28  public:
29   uint8_t id;
30   uint32_t sdu_interval_m_to_s;
31   uint32_t sdu_interval_s_to_m;
32   bool interleaved;
33   bool framed;
34   uint16_t max_transport_latency_m_to_s;
35   uint16_t max_transport_latency_s_to_m;
36 };
37 
38 class ConnectedIsochronousGroup {
39  public:
ConnectedIsochronousGroup(GroupParameters parameters,std::vector<ConnectedIsochronousStream> streams)40   ConnectedIsochronousGroup(GroupParameters parameters,
41                             std::vector<ConnectedIsochronousStream> streams)
42       : parameters_(parameters), streams_(std::move(streams)) {}
43 
44   virtual ~ConnectedIsochronousGroup() = default;
45 
HasConnectedStream()46   bool HasConnectedStream() const {
47     return std::any_of(
48         streams_.begin(), streams_.end(),
49         [&](const ConnectedIsochronousStream& s) { return s.IsConnected(); });
50   }
51 
StreamIsConnected(uint16_t handle)52   bool StreamIsConnected(uint16_t handle) const {
53     return streams_.at(handle).IsConnected();
54   }
55 
HasStreams()56   bool HasStreams() const { return !streams_.empty(); }
57 
GetParameters()58   GroupParameters GetParameters() const { return parameters_; }
59 
GetStreamParameters(uint16_t handle)60   StreamParameters GetStreamParameters(uint16_t handle) const {
61     for (const auto& stream : streams_) {
62       if (stream.GetHandle() == handle) {
63         return stream.GetConfig();
64       }
65     }
66     return StreamParameters{};
67   }
68 
69  private:
70   GroupParameters parameters_;
71   std::vector<ConnectedIsochronousStream> streams_;
72 };
73 
74 }  // namespace rootcanal
75