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