• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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 <iomanip>
20 #include <iostream>
21 #include <sstream>
22 #include <string>
23 #include <type_traits>
24 
25 #include "avrcp_common.h"
26 #include "bt_trace.h"
27 
28 namespace bluetooth {
29 namespace avrcp {
30 
31 #define CASE_RETURN_TEXT(code) \
32   case code:                   \
33     return #code
34 
CTypeText(const CType & type)35 inline std::string CTypeText(const CType& type) {
36   switch (type) {
37     CASE_RETURN_TEXT(CType::CONTROL);
38     CASE_RETURN_TEXT(CType::STATUS);
39     CASE_RETURN_TEXT(CType::NOTIFY);
40     CASE_RETURN_TEXT(CType::ACCEPTED);
41     CASE_RETURN_TEXT(CType::REJECTED);
42     CASE_RETURN_TEXT(CType::STABLE);
43     CASE_RETURN_TEXT(CType::CHANGED);
44     CASE_RETURN_TEXT(CType::INTERIM);
45     default:
46       return "Unknown CType: " + loghex((uint8_t)type);
47   }
48 }
49 
50 inline std::ostream& operator<<(std::ostream& os, const CType& type) {
51   return os << CTypeText(type);
52 }
53 
OpcodeText(const Opcode & opcode)54 inline std::string OpcodeText(const Opcode& opcode) {
55   switch (opcode) {
56     CASE_RETURN_TEXT(Opcode::VENDOR);
57     CASE_RETURN_TEXT(Opcode::UNIT_INFO);
58     CASE_RETURN_TEXT(Opcode::SUBUNIT_INFO);
59     CASE_RETURN_TEXT(Opcode::PASS_THROUGH);
60     default:
61       return "Unknown Opcode: " + loghex((uint8_t)opcode);
62   }
63 }
64 
65 inline std::ostream& operator<<(std::ostream& os, const Opcode& opcode) {
66   return os << OpcodeText(opcode);
67 }
68 
CommandPduText(const CommandPdu & pdu)69 inline std::string CommandPduText(const CommandPdu& pdu) {
70   switch (pdu) {
71     CASE_RETURN_TEXT(CommandPdu::GET_CAPABILITIES);
72     CASE_RETURN_TEXT(CommandPdu::LIST_PLAYER_APPLICATION_SETTING_ATTRIBUTES);
73     CASE_RETURN_TEXT(CommandPdu::LIST_PLAYER_APPLICATION_SETTING_VALUES);
74     CASE_RETURN_TEXT(CommandPdu::GET_CURRENT_PLAYER_APPLICATION_SETTING_VALUE);
75     CASE_RETURN_TEXT(CommandPdu::SET_PLAYER_APPLICATION_SETTING_VALUE);
76     CASE_RETURN_TEXT(CommandPdu::GET_ELEMENT_ATTRIBUTES);
77     CASE_RETURN_TEXT(CommandPdu::GET_PLAY_STATUS);
78     CASE_RETURN_TEXT(CommandPdu::REGISTER_NOTIFICATION);
79     CASE_RETURN_TEXT(CommandPdu::SET_ABSOLUTE_VOLUME);
80     CASE_RETURN_TEXT(CommandPdu::SET_ADDRESSED_PLAYER);
81     CASE_RETURN_TEXT(CommandPdu::PLAY_ITEM);
82     default:
83       return "Unknown Command PDU: " + loghex((uint8_t)pdu);
84   }
85 }
86 
87 inline std::ostream& operator<<(std::ostream& os, const CommandPdu& pdu) {
88   return os << CommandPduText(pdu);
89 }
90 
PacketTypeText(const PacketType & type)91 inline std::string PacketTypeText(const PacketType& type) {
92   switch (type) {
93     CASE_RETURN_TEXT(PacketType::SINGLE);
94     default:
95       return "Unknown Packet Type: " + loghex((uint8_t)type);
96   }
97 }
98 
99 inline std::ostream& operator<<(std::ostream& os, const PacketType& type) {
100   return os << PacketTypeText(type);
101 }
102 
CapabilityText(const Capability & cap)103 inline std::string CapabilityText(const Capability& cap) {
104   switch (cap) {
105     CASE_RETURN_TEXT(Capability::COMPANY_ID);
106     CASE_RETURN_TEXT(Capability::EVENTS_SUPPORTED);
107     default:
108       return "Unknown Capability: " + loghex((uint8_t)cap);
109   }
110 }
111 
112 inline std::ostream& operator<<(std::ostream& os, const Capability& cap) {
113   return os << CapabilityText(cap);
114 }
115 
EventText(const Event & event)116 inline std::string EventText(const Event& event) {
117   switch (event) {
118     CASE_RETURN_TEXT(Event::PLAYBACK_STATUS_CHANGED);
119     CASE_RETURN_TEXT(Event::TRACK_CHANGED);
120     CASE_RETURN_TEXT(Event::PLAYBACK_POS_CHANGED);
121     CASE_RETURN_TEXT(Event::PLAYER_APPLICATION_SETTING_CHANGED);
122     CASE_RETURN_TEXT(Event::NOW_PLAYING_CONTENT_CHANGED);
123     CASE_RETURN_TEXT(Event::AVAILABLE_PLAYERS_CHANGED);
124     CASE_RETURN_TEXT(Event::ADDRESSED_PLAYER_CHANGED);
125     CASE_RETURN_TEXT(Event::UIDS_CHANGED);
126     CASE_RETURN_TEXT(Event::VOLUME_CHANGED);
127     default:
128       return "Unknown Event: " + loghex((uint8_t)event);
129   }
130 }
131 
132 inline std::ostream& operator<<(std::ostream& os, const Event& event) {
133   return os << EventText(event);
134 }
135 
AttributeText(const Attribute & attr)136 inline std::string AttributeText(const Attribute& attr) {
137   switch (attr) {
138     CASE_RETURN_TEXT(Attribute::TITLE);
139     CASE_RETURN_TEXT(Attribute::ARTIST_NAME);
140     CASE_RETURN_TEXT(Attribute::ALBUM_NAME);
141     CASE_RETURN_TEXT(Attribute::TRACK_NUMBER);
142     CASE_RETURN_TEXT(Attribute::TOTAL_NUMBER_OF_TRACKS);
143     CASE_RETURN_TEXT(Attribute::GENRE);
144     CASE_RETURN_TEXT(Attribute::PLAYING_TIME);
145     CASE_RETURN_TEXT(Attribute::DEFAULT_COVER_ART);
146     default:
147       return "Unknown Attribute Value: " + loghex((uint32_t)attr);
148   }
149 }
150 
151 inline std::ostream& operator<<(std::ostream& os, const Attribute& attr) {
152   return os << AttributeText(attr);
153 }
154 
StatusText(const Status & status)155 inline std::string StatusText(const Status& status) {
156   switch (status) {
157     CASE_RETURN_TEXT(Status::INVALID_COMMAND);
158     CASE_RETURN_TEXT(Status::INVALID_PARAMETER);
159     CASE_RETURN_TEXT(Status::PARAMETER_CONTENT_ERROR);
160     CASE_RETURN_TEXT(Status::INTERNAL_ERROR);
161     CASE_RETURN_TEXT(Status::NO_ERROR);
162     CASE_RETURN_TEXT(Status::UIDS_CHANGED);
163     CASE_RETURN_TEXT(Status::RESERVED);
164     CASE_RETURN_TEXT(Status::INVALID_DIRECTION);
165     CASE_RETURN_TEXT(Status::NOT_A_DIRECTORY);
166     CASE_RETURN_TEXT(Status::DOES_NOT_EXIST);
167     CASE_RETURN_TEXT(Status::INVALID_SCOPE);
168     CASE_RETURN_TEXT(Status::RANGE_OUT_OF_BOUNDS);
169     CASE_RETURN_TEXT(Status::FOLDER_ITEM_NOT_PLAYABLE);
170     CASE_RETURN_TEXT(Status::MEDIA_IN_USE);
171     CASE_RETURN_TEXT(Status::NOW_PLAYING_LIST_FULL);
172     CASE_RETURN_TEXT(Status::SEARCH_NOT_SUPPORTED);
173     CASE_RETURN_TEXT(Status::SEARCH_IN_PROGRESS);
174     CASE_RETURN_TEXT(Status::INVALID_PLAYER_ID);
175     CASE_RETURN_TEXT(Status::PLAYER_NOT_BROWSABLE);
176     CASE_RETURN_TEXT(Status::PLAYER_NOT_ADDRESSED);
177     CASE_RETURN_TEXT(Status::NO_VALID_SEARCH_RESULTS);
178     CASE_RETURN_TEXT(Status::NO_AVAILABLE_PLAYERS);
179     CASE_RETURN_TEXT(Status::ADDRESSED_PLAYER_CHANGED);
180     default:
181       return "Unknown Status: " + loghex((uint8_t)status);
182   }
183 }
184 
185 inline std::ostream& operator<<(std::ostream& os, const Status& status) {
186   return os << StatusText(status);
187 }
188 
BrowsePduText(const BrowsePdu & pdu)189 inline std::string BrowsePduText(const BrowsePdu& pdu) {
190   switch (pdu) {
191     CASE_RETURN_TEXT(BrowsePdu::SET_BROWSED_PLAYER);
192     CASE_RETURN_TEXT(BrowsePdu::GET_FOLDER_ITEMS);
193     CASE_RETURN_TEXT(BrowsePdu::CHANGE_PATH);
194     CASE_RETURN_TEXT(BrowsePdu::GET_ITEM_ATTRIBUTES);
195     default:
196       return "Unknown Browse PDU: " + loghex((uint8_t)pdu);
197   }
198 }
199 
200 inline std::ostream& operator<<(std::ostream& os, const BrowsePdu& pdu) {
201   return os << BrowsePduText(pdu);
202 }
203 
ScopeText(const Scope & scope)204 inline std::string ScopeText(const Scope& scope) {
205   switch (scope) {
206     CASE_RETURN_TEXT(Scope::MEDIA_PLAYER_LIST);
207     CASE_RETURN_TEXT(Scope::VFS);
208     CASE_RETURN_TEXT(Scope::SEARCH);
209     CASE_RETURN_TEXT(Scope::NOW_PLAYING);
210     default:
211       return "Unknown Scope: " + loghex((uint8_t)scope);
212   }
213 }
214 
215 inline std::ostream& operator<<(std::ostream& os, const Scope& pdu) {
216   return os << ScopeText(pdu);
217 }
218 
DirectionText(const Direction & dir)219 inline std::string DirectionText(const Direction& dir) {
220   switch (dir) {
221     CASE_RETURN_TEXT(Direction::UP);
222     CASE_RETURN_TEXT(Direction::DOWN);
223     default:
224       return "Unknown Direction: " + loghex((uint8_t)dir);
225   }
226 }
227 
228 inline std::ostream& operator<<(std::ostream& os, const Direction& dir) {
229   return os << DirectionText(dir);
230 }
231 
KeyStateText(const KeyState & state)232 inline std::string KeyStateText(const KeyState& state) {
233   switch (state) {
234     CASE_RETURN_TEXT(KeyState::PUSHED);
235     CASE_RETURN_TEXT(KeyState::RELEASED);
236     default:
237       return "Unknown KeyState: " + loghex((uint8_t)state);
238   }
239 }
240 
241 inline std::ostream& operator<<(std::ostream& os, const KeyState& dir) {
242   return os << KeyStateText(dir);
243 }
244 
PlayerAttributeText(const PlayerAttribute & attr)245 inline std::string PlayerAttributeText(const PlayerAttribute& attr) {
246   switch (attr) {
247     CASE_RETURN_TEXT(PlayerAttribute::EQUALIZER);
248     CASE_RETURN_TEXT(PlayerAttribute::REPEAT);
249     CASE_RETURN_TEXT(PlayerAttribute::SHUFFLE);
250     CASE_RETURN_TEXT(PlayerAttribute::SCAN);
251   }
252   return "Unknown Player Attribute: " + loghex((uint8_t)attr);
253 }
254 
255 inline std::ostream& operator<<(std::ostream& os, const PlayerAttribute& attr) {
256   return os << PlayerAttributeText(attr);
257 }
258 
PlayerRepeatValueText(const PlayerRepeatValue & val)259 inline std::string PlayerRepeatValueText(const PlayerRepeatValue& val) {
260   switch (val) {
261     CASE_RETURN_TEXT(PlayerRepeatValue::OFF);
262     CASE_RETURN_TEXT(PlayerRepeatValue::SINGLE);
263     CASE_RETURN_TEXT(PlayerRepeatValue::ALL);
264     CASE_RETURN_TEXT(PlayerRepeatValue::GROUP);
265   }
266   return "Unknown Player Repeat Value: " + loghex((uint8_t)val);
267 }
268 
269 inline std::ostream& operator<<(std::ostream& os,
270                                 const PlayerRepeatValue& val) {
271   return os << PlayerRepeatValueText(val);
272 }
273 
PlayerShuffleValueText(const PlayerShuffleValue & val)274 inline std::string PlayerShuffleValueText(const PlayerShuffleValue& val) {
275   switch (val) {
276     CASE_RETURN_TEXT(PlayerShuffleValue::OFF);
277     CASE_RETURN_TEXT(PlayerShuffleValue::ALL);
278     CASE_RETURN_TEXT(PlayerShuffleValue::GROUP);
279   }
280   return "Unknown Player Shuffle Value: " + loghex((uint8_t)val);
281 }
282 
283 inline std::ostream& operator<<(std::ostream& os,
284                                 const PlayerShuffleValue& val) {
285   return os << PlayerShuffleValueText(val);
286 }
287 
288 }  // namespace avrcp
289 }  // namespace bluetooth
290